KrishnaCosmic commited on
Commit
1a8995c
·
1 Parent(s): 3f8d939

apply duplicate pr issue

Browse files
Files changed (1) hide show
  1. src/lib/db/queries/issues.ts +14 -9
src/lib/db/queries/issues.ts CHANGED
@@ -114,18 +114,23 @@ export async function getIssues(filters: IssueFilters, page = 1, limit = 10) {
114
 
115
  const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
116
 
117
- const results = await db.select()
118
  .from(issues)
119
  .where(whereClause)
120
- .orderBy(desc(issues.createdAt))
121
- .limit(limit)
122
- .offset(offset);
123
-
124
- const totalResult = await db.select({ count: count() })
125
- .from(issues)
126
- .where(whereClause);
 
 
 
 
127
 
128
- const total = totalResult[0]?.count || 0;
 
129
 
130
  return {
131
  issues: results,
 
114
 
115
  const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
116
 
117
+ const rawResults = await db.select()
118
  .from(issues)
119
  .where(whereClause)
120
+ .orderBy(desc(issues.createdAt));
121
+
122
+ // Deduplicate by githubIssueId — the DB may contain duplicate rows for the
123
+ // same GitHub issue/PR because the primary key is a UUID and
124
+ // onConflictDoNothing() never triggers. Keep the first (most recent) entry.
125
+ const seen = new Set<number>();
126
+ const deduped = rawResults.filter(issue => {
127
+ if (seen.has(issue.githubIssueId)) return false;
128
+ seen.add(issue.githubIssueId);
129
+ return true;
130
+ });
131
 
132
+ const total = deduped.length;
133
+ const results = deduped.slice(offset, offset + limit);
134
 
135
  return {
136
  issues: results,