feat: implement article version content storage and reconstruction logic; enhance article repository with version management

This commit is contained in:
2026-04-07 22:21:16 +08:00
parent d0f0271346
commit 41f8e0621e
9 changed files with 324 additions and 48 deletions
@@ -4,9 +4,6 @@ import (
"context"
"time"
"github.com/jackc/pgx/v5/pgtype"
"github.com/geo-platform/tenant-api/internal/shared/contentstats"
"github.com/geo-platform/tenant-api/internal/tenant/repository/generated"
)
@@ -76,7 +73,7 @@ func (r *workspaceRepository) GetRecentArticles(ctx context.Context, tenantID in
GenerationMode: nullableText(row.GenerationMode),
CreatedAt: timeFromTimestamp(row.CreatedAt),
Title: nullableText(row.Title),
WordCount: resolveWorkspaceWordCount(row.MarkdownContent, intFromInt4(row.WordCount)),
WordCount: intFromInt4(row.WordCount),
SourceLabel: nullableText(row.SourceLabel),
TemplateName: nullableText(row.TemplateName),
})
@@ -107,12 +104,3 @@ func (r *workspaceRepository) GetActivePlanForTenant(ctx context.Context, tenant
EndAt: timeFromTimestamp(row.EndAt),
}, nil
}
func resolveWorkspaceWordCount(markdown pgtype.Text, stored int) int {
if markdown.Valid {
if counted := contentstats.CountWords(markdown.String); counted > 0 {
return counted
}
}
return stored
}