aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/models/lists.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/trpc/models/lists.ts')
-rw-r--r--packages/trpc/models/lists.ts31
1 files changed, 26 insertions, 5 deletions
diff --git a/packages/trpc/models/lists.ts b/packages/trpc/models/lists.ts
index 0968492a..10d7d9bf 100644
--- a/packages/trpc/models/lists.ts
+++ b/packages/trpc/models/lists.ts
@@ -719,6 +719,7 @@ export abstract class List {
id: true,
name: true,
email: true,
+ image: true,
},
},
},
@@ -738,6 +739,7 @@ export abstract class List {
id: true,
name: true,
email: true,
+ image: true,
},
});
@@ -754,6 +756,7 @@ export abstract class List {
name: c.user.name,
// Only show email to the owner for privacy
email: isOwner ? c.user.email : null,
+ image: c.user.image,
},
};
});
@@ -766,6 +769,7 @@ export abstract class List {
name: owner.name,
// Only show owner email to the owner for privacy
email: isOwner ? owner.email : null,
+ image: owner.image,
}
: null,
};
@@ -805,8 +809,8 @@ export abstract class List {
}
abstract get type(): "manual" | "smart";
- abstract getBookmarkIds(ctx: AuthedContext): Promise<string[]>;
- abstract getSize(ctx: AuthedContext): Promise<number>;
+ abstract getBookmarkIds(visitedListIds?: Set<string>): Promise<string[]>;
+ abstract getSize(): Promise<number>;
abstract addBookmark(bookmarkId: string): Promise<void>;
abstract removeBookmark(bookmarkId: string): Promise<void>;
abstract mergeInto(
@@ -816,6 +820,8 @@ export abstract class List {
}
export class SmartList extends List {
+ private static readonly MAX_VISITED_LISTS = 30;
+
parsedQuery: ReturnType<typeof parseSearchQuery> | null = null;
constructor(ctx: AuthedContext, list: ZBookmarkList & { userId: string }) {
@@ -843,12 +849,27 @@ export class SmartList extends List {
return this.parsedQuery;
}
- async getBookmarkIds(): Promise<string[]> {
+ async getBookmarkIds(visitedListIds = new Set<string>()): Promise<string[]> {
+ if (visitedListIds.size >= SmartList.MAX_VISITED_LISTS) {
+ return [];
+ }
+
+ if (visitedListIds.has(this.list.id)) {
+ return [];
+ }
+
+ const newVisitedListIds = new Set(visitedListIds);
+ newVisitedListIds.add(this.list.id);
+
const parsedQuery = this.getParsedQuery();
if (!parsedQuery.matcher) {
return [];
}
- return await getBookmarkIdsFromMatcher(this.ctx, parsedQuery.matcher);
+ return await getBookmarkIdsFromMatcher(
+ this.ctx,
+ parsedQuery.matcher,
+ newVisitedListIds,
+ );
}
async getSize(): Promise<number> {
@@ -894,7 +915,7 @@ export class ManualList extends List {
return this.list.type;
}
- async getBookmarkIds(): Promise<string[]> {
+ async getBookmarkIds(_visitedListIds?: Set<string>): Promise<string[]> {
const results = await this.ctx.db
.select({ id: bookmarksInLists.bookmarkId })
.from(bookmarksInLists)