> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Doc Snapshots 컬렉션

`docSnapshots`에는 댓글이나 변경 내용 추적을 접는(collapse) 편집 직전에 document-updater가 만든 문서 사본이 저장됩니다. document-updater만 이 컬렉션에 쓰며, `services/document-updater/app/js/SnapshotManager.js`에서 씁니다. Web에는 `services/web/app/src/models/DocSnapshot.mjs`에 Mongoose 모델이 있지만 이를 사용하는 코드는 없습니다.

#### 필드

| 필드 | 타입 | 의미 | 출처 |
| - | - | - | - |
| `_id` | ObjectId | 스냅샷 ID. | `SnapshotManager.js:24` |
| `project_id` | ObjectId | 프로젝트. | `SnapshotManager.js:19,26`, `DocSnapshot.mjs:7` |
| `doc_id` | ObjectId | 문서(`docs._id`). | `SnapshotManager.js:20,27`, `DocSnapshot.mjs:8` |
| `version` | Number | 편집 전 문서의 OT 버전. | `SnapshotManager.js:28`, `services/document-updater/app/js/UpdateManager.js:132,264-271`, `DocSnapshot.mjs:9` |
| `lines` | Array of String | 편집 전 문서의 내용. | `SnapshotManager.js:29`, `DocSnapshot.mjs:10` |
| `pathname` | String | 당시 프로젝트 안에서의 문서 경로. | `SnapshotManager.js:30`, `DocSnapshot.mjs:11` |
| `ranges` | Mixed | 편집 전의 `comments`와 `changes`로, `docs.ranges`와 같은 형태입니다([docs](https://ayakaleaf-pro.mintlify.site/ko/dev/data-model/docs-collection.md) 참고). `id`, `op.t`, `metadata.user_id`은 ObjectId로, `metadata.ts`은 Date로 변환됩니다. | `SnapshotManager.js:31,41-68`, `DocSnapshot.mjs:12` |
| `ts` | Date | 스냅샷을 만든 시각. TTL 인덱스가 30일 후 스냅샷을 삭제합니다. | `SnapshotManager.js:32`, `DocSnapshot.mjs:13` |

#### 쓰는 곳

| 코드 | 하는 일 |
| - | - |
| `UpdateManager.js:248-271` | document-updater는 편집을 적용한 뒤, 그 편집이 범위를 접었다면(비게 된 범위가 늘었거나 둘 이상의 범위가 제거된 경우) 편집 전 문서를 기록합니다(`services/document-updater/app/js/RangesManager.js:104-106`). |
| `SnapshotManager.js:17-36` `recordSnapshot` | 스냅샷을 삽입합니다. |

#### 읽는 곳

읽는 코드가 없습니다. Web 모델은 정의되어 있지만 어디에서도 사용되지 않습니다.

#### 인덱스

| 이름 | 키 | 옵션 | 마이그레이션 |
| - | - | - | - |
| `ts_1` | `{ ts: 1 }` | TTL, `expireAfterSeconds: 2592000`(30일) | `tools/migrations/20190912145007_create_docSnapshots_indexes.mjs` |
| `project_id_1_ts_1` | `{ project_id: 1, ts: 1 }` | | `tools/migrations/20200120163346_atlas_recommended_indexes.mjs` |

`20190912145007_create_docSnapshots_indexes.mjs`의 `project_id_1` 인덱스는 `20231101191643_drop_unused_indexes.mjs`에서 삭제되었습니다.

#### 참고

* `UpdateManager.applyUpdate`를 거치는 편집만 스냅샷을 만듭니다. `HistoryOTUpdateManager`가 처리하는 편집은 만들지 않습니다(`UpdateManager.js:74-77`).
* `doc_id`에는 인덱스가 없습니다. 문서의 스냅샷은 `project_id`와 `ts`로 찾은 뒤 `doc_id`로 걸러 내세요.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.