aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/graphql
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-01-12 08:58:04 +0000
committerClaude <noreply@anthropic.com>2026-01-12 08:58:04 +0000
commit8524487824f7332223b24e75ab327bf6ec5eccc9 (patch)
treec44fb10d82e34d55479cefc62496517c749db3b6 /backend/graphql
parent485486c7ff986712ecb09e92217236d276d317c4 (diff)
downloadfeedaka-8524487824f7332223b24e75ab327bf6ec5eccc9.tar.gz
feedaka-8524487824f7332223b24e75ab327bf6ec5eccc9.tar.zst
feedaka-8524487824f7332223b24e75ab327bf6ec5eccc9.zip
refactor: deduplicate articles at insertion time instead of query time
Change deduplication strategy from query-time (ROW_NUMBER window function) to insertion-time (global guid check before insert). Benefits: - Simpler queries without CTE/window functions - Consistent read state (no duplicate articles to manage) - Better query performance (no per-query deduplication overhead) Changes: - Add CheckArticleExistsByGUID query for global guid lookup - Add migration to remove existing duplicate articles - Modify fetchOneFeed and AddFeed to skip duplicates on insert - Revert GetUnreadArticles/GetReadArticles to simple queries
Diffstat (limited to 'backend/graphql')
-rw-r--r--backend/graphql/resolver/schema.resolvers.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/backend/graphql/resolver/schema.resolvers.go b/backend/graphql/resolver/schema.resolvers.go
index 46c39e7..c3f6f0a 100644
--- a/backend/graphql/resolver/schema.resolvers.go
+++ b/backend/graphql/resolver/schema.resolvers.go
@@ -43,8 +43,18 @@ func (r *mutationResolver) AddFeed(ctx context.Context, url string) (*model.Feed
return nil, fmt.Errorf("failed to insert feed: %w", err)
}
- // Insert articles from the feed
+ // Insert articles from the feed (skip duplicates by guid)
for _, item := range feed.Items {
+ // Check if article with same GUID already exists globally
+ exists, err := r.Queries.CheckArticleExistsByGUID(ctx, item.GUID)
+ if err != nil {
+ fmt.Printf("Failed to check article existence: %v\n", err)
+ continue
+ }
+ if exists == 1 {
+ // Article already exists, skip
+ continue
+ }
_, err = r.Queries.CreateArticle(ctx, db.CreateArticleParams{
FeedID: dbFeed.ID,
Guid: item.GUID,