> ## 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.

# Collection Doc Snapshots

`docSnapshots` lưu các bản sao của một doc mà document-updater chụp ngay trước một lần chỉnh sửa làm thu gọn bình luận hoặc thay đổi được theo dõi. Chỉ document-updater ghi vào nó, trong `services/document-updater/app/js/SnapshotManager.js`. Web có một model Mongoose trong `services/web/app/src/models/DocSnapshot.mjs`, nhưng không có mã nào dùng nó.

#### Các trường

| Trường | Kiểu | Ý nghĩa | Nguồn |
| - | - | - | - |
| `_id` | ObjectId | Id của snapshot. | `SnapshotManager.js:24` |
| `project_id` | ObjectId | Dự án. | `SnapshotManager.js:19,26`, `DocSnapshot.mjs:7` |
| `doc_id` | ObjectId | Doc (`docs._id`). | `SnapshotManager.js:20,27`, `DocSnapshot.mjs:8` |
| `version` | Number | Phiên bản OT của doc trước khi chỉnh sửa. | `SnapshotManager.js:28`, `services/document-updater/app/js/UpdateManager.js:132,264-271`, `DocSnapshot.mjs:9` |
| `lines` | Array of String | Nội dung của doc trước khi chỉnh sửa. | `SnapshotManager.js:29`, `DocSnapshot.mjs:10` |
| `pathname` | String | Đường dẫn của doc trong dự án tại thời điểm đó. | `SnapshotManager.js:30`, `DocSnapshot.mjs:11` |
| `ranges` | Mixed | `comments` và `changes` trước khi chỉnh sửa, có cùng cấu trúc với `docs.ranges` (xem [docs](https://ayakaleaf-pro.mintlify.site/vi/dev/data-model/docs-collection.md)). `id`, `op.t` và `metadata.user_id` được chuyển thành ObjectId, còn `metadata.ts` thành Date. | `SnapshotManager.js:31,41-68`, `DocSnapshot.mjs:12` |
| `ts` | Date | Thời điểm chụp snapshot. Chỉ mục TTL xóa snapshot sau 30 ngày. | `SnapshotManager.js:32`, `DocSnapshot.mjs:13` |

#### Ai ghi

| Mã | Chức năng |
| - | - |
| `UpdateManager.js:248-271` | Sau khi áp dụng một chỉnh sửa, document-updater ghi lại doc như trước khi chỉnh sửa nếu chỉnh sửa đó thu gọn các vùng: có thêm vùng trở nên rỗng, hoặc hơn một vùng bị xóa (`services/document-updater/app/js/RangesManager.js:104-106`). |
| `SnapshotManager.js:17-36` `recordSnapshot` | Chèn snapshot. |

#### Ai đọc

Không có mã nào đọc nó. Model của web được định nghĩa nhưng không được dùng ở đâu.

#### Chỉ mục

| Tên | Khóa | Tùy chọn | Migration |
| - | - | - | - |
| `ts_1` | `{ ts: 1 }` | TTL, `expireAfterSeconds: 2592000` (30 ngày) | `tools/migrations/20190912145007_create_docSnapshots_indexes.mjs` |
| `project_id_1_ts_1` | `{ project_id: 1, ts: 1 }` | | `tools/migrations/20200120163346_atlas_recommended_indexes.mjs` |

Chỉ mục `project_id_1` của `20190912145007_create_docSnapshots_indexes.mjs` đã bị xóa bởi `20231101191643_drop_unused_indexes.mjs`.

#### Ghi chú

* Chỉ những chỉnh sửa đi qua `UpdateManager.applyUpdate` mới chụp snapshot. Chỉnh sửa do `HistoryOTUpdateManager` xử lý thì không (`UpdateManager.js:74-77`).
* Không có chỉ mục trên `doc_id`. Hãy tìm snapshot của một doc theo `project_id` và `ts`, rồi lọc theo `doc_id`.


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