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

# Project History Labels 集合

`projectHistoryLabels` 保存使用者在歷史檢視中為版本加上的標籤，每個標籤一個文件。它歸 project-history 所有，並由其在 `services/project-history/app/js/LabelsManager.js` 中寫入；沒有 Mongoose schema。Web 只透過 project-history API 存取它。

#### 欄位

| 欄位 | 型別 | 含義 | 來源 |
| - | - | - | - |
| `_id` | ObjectId | 標籤 ID。 | `LabelsManager.js:81-85` |
| `project_id` | ObjectId | 專案。 | `LabelsManager.js:73` |
| `comment` | String | 標籤文字。 | `LabelsManager.js:74` |
| `version` | Number | 標籤指向的專案歷史版本。 | `LabelsManager.js:75` |
| `created_at` | Date | 建立標籤的時間；請求可以傳入自己的時間，否則使用目前時間。 | `LabelsManager.js:70`, `76` |
| `user_id` | ObjectId | 建立標籤的使用者。請求中沒有使用者時省略。 | `LabelsManager.js:78-80` |

#### 寫入方

| 程式碼 | 作用 |
| - | - |
| `services/project-history/app/js/LabelsManager.js:44-90` | `createLabel`：插入一個標籤，用於 project-history `POST /project/:project_id/labels`（`services/project-history/app/js/HttpController.js:1134-1171`）。使用者新增標籤時，Web 會帶上使用者 ID 呼叫它（`services/web/app/src/Features/History/HistoryController.mjs:529-546`）。 |
| `LabelsManager.js:113-126` | `deleteLabel`：刪除專案的一個標籤，用於 `DELETE /project/:project_id/labels/:label_id`。專案擁有者刪除標籤時，Web 使用它（`HistoryController.mjs:649-670`）。 |
| `LabelsManager.js:92-111` | `deleteLabelForUser`：僅當標籤由該使用者建立時才刪除，用於 `DELETE /project/:project_id/user/:user_id/labels/:label_id`。其他所有人刪除標籤時，Web 使用它。 |
| `LabelsManager.js:128-143` | `transferLabels`：把一個使用者的所有標籤轉移給另一個使用者，用於 `POST /user/:from_user/labels/transfer/:to_user`（`services/project-history/app/js/Router.js:52-55`）。Web 中沒有任何程式碼呼叫這個路由。 |
| `LabelsManager.js:7-25` | `cloneLabels`：把一個專案的標籤複製到另一個專案，用於 project-history `POST /project/:project_id/clone`（`HttpController.js:113`），Web 中沒有任何程式碼呼叫它。 |

#### 讀取方

| 程式碼 | 作用 |
| - | - |
| `LabelsManager.js:27-42` | `getLabels`：專案的所有標籤，以 `{ id, comment, version, user_id, created_at }` 的形式回傳（`LabelsManager.js:163-171`）。由 `GET /project/:project_id/labels` 使用（`HttpController.js:1076-1100`），Web 為歷史檢視呼叫它並填入使用者名稱（`HistoryController.mjs:488-499`）。 |
| `services/project-history/app/js/SummarizedUpdatesManager.js:57` | 把標籤加入歷史更新清單。 |

#### 索引

| 名稱 | 鍵 | 選項 | 遷移 |
| - | - | - | - |
| `project_id_1` | `{ project_id: 1 }` | | `tools/migrations/20190912145019_create_projectHistoryLabels_indexes.mjs` |
| `user_id_1` | `{ user_id: 1 }` | | `tools/migrations/20190912145019_create_projectHistoryLabels_indexes.mjs` |

#### 說明

* 插入標籤之前，project-history 會處理該專案排隊中的更新，並檢查 history-v1 中是否有該版本的 chunk，除非請求傳送了 `validate_exists: false`（`LabelsManager.js:53-59`、`173-195`；`HttpController.js:1109-1115`）。
* 刪除專案時，沒有程式碼會刪除其標籤：project-history `DELETE /project/:project_id` 只清除同步狀態和失敗記錄（`HttpController.js:1363-1396`），其他服務也不會碰這個集合。


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