The Memo Service is the core backend service responsible for all memo-related operations in the Memos application. It provides a comprehensive gRPC API for creating, reading, updating, and deleting memos, along with advanced features like tags, attachments, relations, comments, and reactions. The service handles visibility controls, permission checks, content processing, and real-time event broadcasting.
The Memo Service is implemented as part of the APIV1Service struct and provides the server-side implementation of the MemoService gRPC interface. It sits between the API gateway and the data storage layer, orchestrating business logic and coordinating with other services.
Sources: server/router/api/v1/memo_service.go70-498 proto/api/v1/memo_service.proto17-147 proto/gen/api/v1/memo_service.pb.gw.go40-152 server/router/api/v1/memo_relation_service.go16-51 server/router/api/v1/reaction_service.go60-109
The CreateMemo operation creates a new memo with validation, content processing, and optional attachments and relations.
Processing Flow:
s.fetchCurrentUser(ctx) server/router/api/v1/memo_service.go71ValidateAndGenerateUID server/router/api/v1/memo_service.go79CreateTime, UpdateTime) server/router/api/v1/memo_service.go92-99memopayload.RebuildMemoPayload to extract metadata and tags server/router/api/v1/memo_service.go101-110s.Store.CreateMemo server/router/api/v1/memo_service.go115DispatchMemoCreatedWebhook server/router/api/v1/memo_service.go157s.SSEHub.Broadcast (skipped if SSE is suppressed) server/router/api/v1/memo_service.go162-169Sources: server/router/api/v1/memo_service.go70-176
The ListMemos operation provides flexible memo listing with advanced filtering and pagination.
PUBLIC memos. Authenticated users see their own memos plus PUBLIC and PROTECTED memos server/router/api/v1/memo_service.go218-228NORMAL or ARCHIVED status. Archived memos are only visible to their creator server/router/api/v1/memo_service.go188-199parseMemoOrderBy, defaulting to creation time descending server/router/api/v1/memo_service.go202-209Sources: server/router/api/v1/memo_service.go178-232
Comments are implemented as memos linked to a parent memo via a COMMENT relation.
CreateMemoComment internally calls CreateMemo but wraps the context with withSuppressSSE to prevent duplicate broadcast events for the new memo server/router/api/v1/memo_service.go30-32 server/router/api/v1/memo_service.go498-533MemoRelation_COMMENT is automatically created between the parent and the comment proto/gen/api/v1/memo_service.pb.go91Reactions allow users to add emojis (e.g., "👍", "❤️") to memos.
UpsertMemoReaction checks memo visibility before allowing a reaction. If the memo is PRIVATE, only the creator or a superuser can react server/router/api/v1/reaction_service.go83-85SSEHub broadcast with types SSEEventReactionUpserted or SSEEventReactionDeleted server/router/api/v1/reaction_service.go106-161Sources: server/router/api/v1/reaction_service.go15-181 server/router/api/v1/memo_service.go22-37
Relations define links between memos, such as references or comments.
| Type | Code Symbol | Description |
|---|---|---|
| Reference | MemoRelation_REFERENCE | A standard link/reference to another memo. |
| Comment | MemoRelation_COMMENT | A hierarchical link representing a comment. |
Internal Logic:
SetMemoRelations replaces all existing REFERENCE type relations for a memo server/router/api/v1/memo_relation_service.go54-61Sources: server/router/api/v1/memo_relation_service.go16-91 store/memo_relation.go9-14
The service manages file attachments associated with memos. SetMemoAttachments allows replacing the full set of attachments for a memo.
normalizeMemoAttachmentRequest ensures that only valid attachments owned by the user (or accessible by superusers) are added server/router/api/v1/memo_attachment_service.go102-125Sources: server/router/api/v1/memo_attachment_service.go16-185
When retrieving memos, the service converts internal store.Memo objects into v1pb.Memo messages.
getMemoContentSnippet server/router/api/v1/memo_service_converter.go76-80Sources: server/router/api/v1/memo_service_converter.go23-83
The system supports multiple database drivers (SQLite, MySQL, PostgreSQL) for managing relations.
ON CONFLICT (memo_id, related_memo_id, type) DO UPDATE and RETURNING store/db/postgres/memo_relation.go20-21Sources: store/db/postgres/memo_relation.go12-173 store/memo_relation.go43-53
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.