Anyone interested in tree labels? #4960
chaoliu719
started this conversation in
General
Replies: 1 comment
-
Memos 标签 API 破坏性重构设计 V1🎯 设计原则
🚨 破坏性修改概览1. 移除现有 Memo 级别 Tag 操作
2. 数据模型增强
📊 新的数据结构TagNode 增强 (
|
操作 | HTTP 方法 | URL | 说明 |
---|---|---|---|
列出标签 | GET | /api/v1/tags?path_prefix=...&include_memo_ids=... |
支持前缀过滤 |
获取标签 | GET | /api/v1/tags/{encoded_tag_path}?include_memo_ids=true |
获取单个标签详情 |
重命名标签 | PATCH | /api/v1/tags/{encoded_old_path}:rename |
请求体包含新路径 |
删除标签 | DELETE | /api/v1/tags/{encoded_tag_path}?strategy=... |
从内容中移除标签 |
批量删除 memos | DELETE | /api/v1/memos?tag_path=...&include_children=...&dry_run=... |
删除包含标签的 memos |
📋 请求/响应消息
核心请求消息
message ListTagsRequest {
// Query parameter: ?path_prefix=/work
string path_prefix = 1;
// Query parameter: ?include_memo_ids=true
// Server default: false if not specified
bool include_memo_ids = 2;
// Query parameter: ?include_hierarchy=true
// Server default: true if not specified
bool include_hierarchy = 3;
}
message GetTagRequest {
// Path parameter: /api/v1/tags/{tag_path}
// URL encoded if contains '/' (e.g., %2Fwork%2Fproject1)
string tag_path = 1 [(google.api.field_behavior) = REQUIRED];
// Query parameter: ?include_memo_ids=true
// Server default: true if not specified
bool include_memo_ids = 2;
}
message RenameTagRequest {
// Path parameter: /api/v1/tags/{old_tag_path}:rename
string old_tag_path = 1 [(google.api.field_behavior) = REQUIRED];
// Request body field
string new_tag_path = 2 [(google.api.field_behavior) = REQUIRED];
// Request body field - Server default: true if not specified
bool move_children = 3;
}
message DeleteTagRequest {
// Path parameter: /api/v1/tags/{tag_path}
string tag_path = 1 [(google.api.field_behavior) = REQUIRED];
enum DeleteStrategy {
REMOVE_FROM_CONTENT = 0; // Remove tag from all memo content
DELETE_RELATED_MEMOS = 1; // Delete memos containing this tag
}
// Query parameter: ?strategy=REMOVE_FROM_CONTENT
// Server default: REMOVE_FROM_CONTENT if not specified
DeleteStrategy strategy = 2;
}
message BatchDeleteMemosByTagRequest {
// Query parameter: ?tag_path=/work/project1
string tag_path = 1 [(google.api.field_behavior) = REQUIRED];
// Query parameter: ?include_children=true
// Server default: true if not specified
bool include_children = 2;
// Query parameter: ?dry_run=true
// Server default: false if not specified
bool dry_run = 3;
}
统一的响应结构
message TagWithMemos {
memos.store.TagNode tag_node = 1;
// Direct memo count (excluding child tags)
int32 direct_memo_count = 2;
// Total memo count (including child tags)
int32 total_memo_count = 3;
// Child tag paths
repeated string child_paths = 4;
// Parent tag path
string parent_path = 5;
}
message ListTagsResponse {
repeated TagWithMemos tags = 1;
int32 total_count = 2;
}
message GetTagResponse {
TagWithMemos tag = 1;
}
message RenameTagResponse {
// Affected memo IDs
repeated string affected_memo_ids = 1;
// Old and new tag paths that were changed
map<string, string> renamed_paths = 2; // old_path -> new_path
}
message DeleteTagResponse {
// Memo IDs that had this tag removed
repeated string affected_memo_ids = 1;
// Tag paths that were deleted
repeated string deleted_tag_paths = 2;
}
message BatchDeleteMemosByTagResponse {
repeated string deleted_memo_ids = 1;
int32 deleted_count = 2;
repeated string affected_tag_paths = 3;
}
🔄 数据流和生命周期
Tag 生命周期管理
- 创建:memo 内容解析时自动创建 TagNode 并填充 memo_ids
- 更新:memo 内容变更时,更新相关 TagNode 的 memo_ids
- 删除:memo_ids 为空的 TagNode 自动清理
层级查询逻辑
-- 查找所有 /work 相关的标签(包括子标签)
SELECT * FROM tag_nodes WHERE full_path LIKE '/work%'
-- 查找所有使用 /work 标签的 memos(包括子标签的 memos)
SELECT DISTINCT memo_id FROM tag_nodes
WHERE full_path LIKE '/work%'
AND memo_id IN (SELECT unnest(memo_ids))
重命名操作流程
- 验证:检查新路径是否已存在
- 收集:获取所有需要重命名的标签路径(包括子标签)
- 更新:在事务中更新所有相关的 memo 内容和 TagNode 记录
- 返回:返回所有受影响的 memo_ids 和路径映射
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I just moved from Flomo, and there are some nice features that don't seem to be there, and I wonder if you need them.
Current system:
Tag Tree System:
Migration Ideas:
Difficulties:
Beta Was this translation helpful? Give feedback.
All reactions