Skip to content

Commit fa4c980

Browse files
committed
add index to task schema
1 parent 99c31ce commit fa4c980

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/convex/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default defineSchema(
77
taskBody: v.string(),
88
isCompleted: v.boolean(),
99
user_id: v.string()
10-
})
10+
}).index('by_user_id', ['user_id'])
1111
},
1212
{
1313
schemaValidation: true

src/convex/tasks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ async function authorizeTaskAccess(
1717
export const get = query({
1818
args: { user_id: v.string() },
1919
handler: async (ctx, args) => {
20-
const tasks = await ctx.db.query('tasks').collect();
21-
return tasks.filter((task) => task.user_id === args.user_id);
20+
return await ctx.db
21+
.query('tasks')
22+
.withIndex('by_user_id', (q) => q.eq('user_id', args.user_id))
23+
.collect();
2224
}
2325
});
2426

0 commit comments

Comments
 (0)