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

# Dropbox Entities 컬렉션

`dropboxEntities`는 Dropbox 동기화가 프로젝트와 한 사용자의 Dropbox 사이에서 복사한 파일마다 문서 하나와, 잠깐 존재하는 tombstone을 담습니다. 이 컬렉션은 Dropbox 동기화에 속합니다. third-party-datastore(`services/third-party-datastore/app/js/StateManager.mjs`)가 쓰고 읽으며, `dropbox` 웹 모듈(`services/web/modules/dropbox/app/src/DropboxHandler.mjs`)이 비웁니다. Mongoose 스키마는 없습니다.

#### 필드

| 필드 | 타입 | 의미 | 출처 |
| - | - | - | - |
| `_id` | ObjectId | 삽입 시 드라이버가 설정합니다. | `StateManager.mjs:46,97` |
| `overleaf.userId` | ObjectId | 파일이 있는 Dropbox의 사용자입니다. 모든 문서에 설정됩니다. | `StateManager.mjs:48,98` |
| `overleaf.projectId` | ObjectId | doc 또는 파일의 프로젝트입니다. 알려진 경우 설정되며, tombstone에는 없습니다. | `StateManager.mjs:49-51` |
| `overleaf.id` | ObjectId | 프로젝트 `rootFolder`에 있는 doc 또는 파일의 `_id`입니다. 알려진 경우 설정됩니다. | `StateManager.mjs:52` |
| `overleaf.type` | String | `doc` 또는 `file`입니다. 현재 코드는 이 값을 쓰지만 읽지는 않습니다. | `StateManager.mjs:53`; 값은 `services/web/app/src/Features/ThirdPartyDataStore/TpdsUpdateSender.mjs:35,96` 및 `UpdateMerger.mjs:104,119`에서 옴 |
| `dropbox.id` | String | Dropbox 파일 메타데이터에 있는 파일의 `id`입니다. tombstone에는 설정되지 않습니다. | `StateManager.mjs:56` |
| `dropbox.pathLower` | String | Dropbox에서의 파일 경로로, 소문자이며 끝에 슬래시가 없습니다. 파일이나 그 프로젝트 폴더가 이동하면 갱신됩니다. | `StateManager.mjs:14-16,57,91,99` |
| `dropbox.rev` | String | 마지막 동기화 시점의 Dropbox 리비전입니다. 다음 업로드가 이를 보내므로 Dropbox에서 변경된 파일을 덮어쓰지 않습니다. | `StateManager.mjs:58`, `JobProcessor.mjs:114-122` |
| `dropbox.contentHash` | String | 마지막 동기화 시점의 Dropbox 콘텐츠 해시입니다. 같은 해시를 가진 목록의 파일은 우리 자신의 업로드이거나 이미 적용된 것이므로 건너뜁니다. | `StateManager.mjs:59`, `PullManager.mjs:147-149` |
| `tombstone` | Boolean | `true`는 third-party-datastore가 직접 Dropbox에서 삭제하거나 다른 곳으로 옮긴 경로를 표시합니다. Dropbox가 그 삭제를 다시 알려 와도 프로젝트에는 적용되지 않습니다. | `StateManager.mjs:100`, `PullManager.mjs:189-192` |
| `createdAt` | Date | tombstone 전용: 만들어진 시각입니다. 완료된 pull은 시작 전에 만들어진 tombstone을 제거합니다. | `StateManager.mjs:101,115-121` |

tombstone에는 `overleaf.userId`, `dropbox.pathLower`, `tombstone`, `createdAt`만 있습니다(`StateManager.mjs:96-103`).

#### 쓰는 곳

| 코드 | 하는 일 |
| - | - |
| `services/third-party-datastore/app/js/StateManager.mjs:35-62` (`recordEntity`) | 같은 `dropbox.id`, `dropbox.pathLower` 또는 `overleaf.id`를 가진 사용자의 문서를 삭제한 다음 새 상태를 삽입합니다. |
| `services/third-party-datastore/app/js/JobProcessor.mjs:102-134` (`addEntity`) | Overleaf에서 Dropbox로 업로드한 뒤 doc 또는 파일을 기록합니다(`:125-133`). |
| `services/third-party-datastore/app/js/PullManager.mjs:142-177` (`applyFile`) | web이 프로젝트에 적용한 뒤 Dropbox 파일을 기록합니다(`:168-176`). |
| `StateManager.mjs:80-94` (`moveEntities`) | 이동된 경로 아래의 `dropbox.pathLower`를 다시 씁니다: 프로젝트 이름 변경(`JobProcessor.mjs:195`)과 파일 또는 폴더 이동(`JobProcessor.mjs:239`). |
| `StateManager.mjs:96-103` (`addTombstone`) | Dropbox에서의 삭제(`JobProcessor.mjs:153`), 프로젝트 이름 변경(`:202`) 또는 이동(`:240`) 후에 실행됩니다. |
| `StateManager.mjs:72-78` (`removeEntities`) | tombstone을 제외하고 경로와 그 아래의 항목을 삭제합니다: Overleaf에서 삭제한 뒤(`JobProcessor.mjs:152`) 또는 Dropbox에서 삭제한 뒤(`PullManager.mjs:206`). |
| `StateManager.mjs:115-121` (`clearTombstones`) | pull이 끝날 때 실행됩니다(`PullManager.mjs:31,69`). |
| `StateManager.mjs:186-190` (`removeUserState`), `services/third-party-datastore/app/js/QueueWorker.mjs:43`에서 호출 | third-party-datastore가 더 이상 사용할 수 없는 계정의 연결을 해제할 때 사용자의 문서를 모두 삭제합니다. |
| `DropboxHandler.mjs:142-146` (`removeUserState`) | 연결할 때(`:125`), 연결을 해제할 때(`:183`), 삭제된 사용자가 만료될 때(`services/web/modules/dropbox/index.mjs:62-64`) 사용자의 문서를 모두 삭제합니다. |
| `DropboxHandler.mjs:150-154` (`removeProjectState`) | 삭제된 프로젝트가 만료될 때 프로젝트의 문서를 삭제합니다(`index.mjs:54-56`). |

#### 읽는 곳

| 코드 | 하는 일 |
| - | - |
| `StateManager.mjs:64-70` (`findEntityByPath`) | 업로드 전에 `dropbox.rev`를(`JobProcessor.mjs:114`), Dropbox 파일을 적용하기 전에 `dropbox.contentHash`를 가져옵니다(`PullManager.mjs:147`). |
| `StateManager.mjs:106-112` (`findTombstone`) | 보고된 삭제를 해당 경로나 그 상위 경로에서 확인합니다(`PullManager.mjs:189`). |
| `StateManager.mjs:160-175` (`getSyncedPaths`) | 커서를 재설정한 뒤 동기화된 파일 경로를 나열하여, 목록에 없는 파일을 삭제된 것으로 간주하게 합니다(`PullManager.mjs:74-85`). |

#### 인덱스

| 이름 | 키 | 옵션 | 마이그레이션 |
| - | - | - | - |
| `_id_` | `_id: 1` | | default |
| `overleaf_userId_1_overleaf_projectId_1` | `overleaf.userId: 1, overleaf.projectId: 1` | | `tools/migrations/20250130104049_create_dropboxEntities_userId_projectId_index.mjs` |

`20220811111800_create_dropboxEntities_index.mjs`와 `20220825160708_recreate_dropboxEntities.mjs`에는 `saas` 태그만 있으므로, CE에는 `(overleaf.userId, dropbox.id)` 및 `(overleaf.userId, overleaf.id)`에 대한 고유 인덱스도, `dropbox.pathLower`에 대한 해시 인덱스도 없습니다.

#### 참고

* 고유성은 `recordEntity`에서 삽입할 때마다 먼저 수행하는 삭제로만 유지됩니다(`StateManager.mjs:38-45`). `StateManager.mjs:3-11`의 주석은 고유 인덱스를 언급하지만 CE에는 없습니다.
* 사용자와 경로로 하는 쿼리(`findEntityByPath`, `findTombstone`, `removeEntities`)는 `overleaf.userId`에 대해서만 인덱스를 사용합니다.


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