feat(spoons): find owned spoons by pushed repo (indexed)

This commit is contained in:
Gabriel Brown
2026-07-11 14:12:30 -04:00
parent f7c3aa6482
commit 68dc7bb4ee
3 changed files with 207 additions and 2 deletions
+2 -1
View File
@@ -135,7 +135,8 @@ const applicationTables = {
.index('by_owner', ['ownerId'])
.index('by_owner_status', ['ownerId', 'status'])
.index('by_owner_provider', ['ownerId', 'provider'])
.index('by_upstream', ['provider', 'upstreamOwner', 'upstreamRepo']),
.index('by_upstream', ['provider', 'upstreamOwner', 'upstreamRepo'])
.index('by_fork', ['provider', 'forkOwner', 'forkRepo']),
spoonRepositoryStates: defineTable({
spoonId: v.id('spoons'),
ownerId: v.id('users'),
+40 -1
View File
@@ -1,6 +1,6 @@
import { ConvexError, v } from 'convex/values';
import type { Doc } from './_generated/dataModel';
import type { Doc, Id } from './_generated/dataModel';
import {
internalMutation,
internalQuery,
@@ -221,6 +221,45 @@ export const getOwnedForAction = internalQuery({
},
});
export const findForRepo = internalQuery({
args: { owner: v.string(), repo: v.string() },
handler: async (
ctx,
{ owner, repo },
): Promise<{ spoonId: Id<'spoons'>; ownerId: Id<'users'> }[]> => {
const [upstreamMatches, forkMatches] = await Promise.all([
ctx.db
.query('spoons')
.withIndex('by_upstream', (q) =>
q
.eq('provider', 'github')
.eq('upstreamOwner', owner)
.eq('upstreamRepo', repo),
)
.collect(),
ctx.db
.query('spoons')
.withIndex('by_fork', (q) =>
q
.eq('provider', 'github')
.eq('forkOwner', owner)
.eq('forkRepo', repo),
)
.collect(),
]);
const seen = new Set<Id<'spoons'>>();
const results: { spoonId: Id<'spoons'>; ownerId: Id<'users'> }[] = [];
for (const spoon of [...upstreamMatches, ...forkMatches]) {
if (spoon.status === 'archived') continue;
if (seen.has(spoon._id)) continue;
seen.add(spoon._id);
results.push({ spoonId: spoon._id, ownerId: spoon.ownerId });
}
return results;
},
});
export const createManual = mutation({
args: {
name: v.string(),