Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

태그 팔로우 로더 사용 #2815

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions apps/website/src/lib/server/graphql/schemas/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NotFoundError } from '$lib/errors';
import { redis, useCache } from '$lib/server/cache';
import {
database,
inArray,
notInArray,
Posts,
PostTags,
Expand Down Expand Up @@ -132,12 +133,24 @@ Tag.implement({
return false;
}

const follows = await database
.select({ id: TagFollows.id })
.from(TagFollows)
.where(and(eq(TagFollows.tagId, tag.id), eq(TagFollows.userId, context.session.userId)));
const loader = context.loader({
name: 'tagFollows(tagId)',
nullable: true,
load: async (tagIds: string[]) => {
if (!context.session) {
return [];
}

return database
.select()
.from(TagFollows)
.where(and(inArray(TagFollows.tagId, tagIds), eq(TagFollows.userId, context.session.userId)));
},

key: (tagFollow) => tagFollow?.tagId,
});

return follows.length > 0;
return await loader.load(tag.id).then((follow) => !!follow);
},
}),

Expand Down