feat: Refactor wiki page update logic for improved version control
- Enhanced the UpdatePage and UpdateMeta methods to differentiate between user-visible content changes and bookkeeping updates, ensuring the version number is only incremented for actual content modifications. - Updated the WikiPage struct and associated interfaces to reflect the new versioning policy, improving clarity on when the version is modified. - Improved documentation for methods to clarify their intended use and behavior regarding versioning and metadata updates.
This commit is contained in:
@@ -14,13 +14,17 @@ type WikiPageService interface {
|
||||
// bidirectional link references, and syncs to chunks for retrieval.
|
||||
CreatePage(ctx context.Context, page *types.WikiPage) (*types.WikiPage, error)
|
||||
|
||||
// UpdatePage updates an existing wiki page, re-parses links,
|
||||
// updates bidirectional references, increments version, and re-syncs chunks.
|
||||
// Use for content changes visible to the user.
|
||||
// UpdatePage updates an existing wiki page, re-parses links, and updates
|
||||
// bidirectional references. The `version` field is incremented only when
|
||||
// a user-visible content field (title, content, summary, page_type,
|
||||
// status) actually differs from the stored value — bookkeeping-only
|
||||
// writes (e.g. refreshing source_refs after a same-content re-ingest) are
|
||||
// persisted without bumping the version.
|
||||
UpdatePage(ctx context.Context, page *types.WikiPage) (*types.WikiPage, error)
|
||||
|
||||
// UpdatePageMeta updates only metadata (status, source_refs) without
|
||||
// incrementing version or re-parsing links. Use for publish/archive/source ref changes.
|
||||
// UpdatePageMeta updates only metadata (status, source_refs, etc.) without
|
||||
// incrementing version or re-parsing links. Use for publish/archive/source
|
||||
// ref changes driven by internal reconciliation.
|
||||
UpdatePageMeta(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// GetPageBySlug retrieves a wiki page by its slug within a knowledge base.
|
||||
@@ -87,10 +91,16 @@ type WikiPageRepository interface {
|
||||
// Create inserts a new wiki page record.
|
||||
Create(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// Update updates an existing wiki page record (increments version — content changes).
|
||||
// Update rewrites a wiki page record with optimistic locking and
|
||||
// unconditionally increments `version`. Callers are responsible for
|
||||
// deciding whether the edit is user-visible — the service layer uses
|
||||
// UpdateMeta for bookkeeping-only writes instead.
|
||||
Update(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// UpdateMeta updates only metadata fields (links, status, source_refs) without version bump.
|
||||
// UpdateMeta updates bookkeeping / provenance fields (in/out links,
|
||||
// status, source_refs, chunk_refs, page_metadata, updated_at) without
|
||||
// touching `version`. Safe for link maintenance, re-ingest with an
|
||||
// unchanged body, and status-only transitions.
|
||||
UpdateMeta(ctx context.Context, page *types.WikiPage) error
|
||||
|
||||
// GetByID retrieves a wiki page by its unique ID.
|
||||
|
||||
@@ -84,7 +84,11 @@ type WikiPage struct {
|
||||
OutLinks StringArray `json:"out_links" gorm:"type:json"`
|
||||
// Arbitrary metadata (tags, categories, dates, etc.)
|
||||
PageMetadata JSON `json:"page_metadata" gorm:"column:page_metadata;type:json"`
|
||||
// Version number, incremented on each update
|
||||
// Version number. Incremented only when a user-visible content field
|
||||
// (title, content, summary, page_type, status) actually changes; pure
|
||||
// bookkeeping writes (link maintenance, same-content re-ingest, status
|
||||
// sync from background jobs) leave it untouched so it can be used as a
|
||||
// real "the page was edited" signal.
|
||||
Version int `json:"version" gorm:"default:1"`
|
||||
// Creation time
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
Reference in New Issue
Block a user