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

Non-webpage bookmarks duplication problem #364 #488

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
22 changes: 21 additions & 1 deletion packages/trpc/routers/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ async function getBookmark(ctx: AuthedContext, bookmarkId: string) {
return toZodSchema(bookmark);
}

async function attemptToDedupLinkWithBookmarkAssets(
ctx: AuthedContext,
url: string,
) {
// Check if the URL was maybe stored as bookmarkAsset instead
const assetResult = await ctx.db
.select({
id: bookmarkAssets.id,
})
.from(bookmarkAssets)
.leftJoin(bookmarks, eq(bookmarks.id, bookmarkAssets.id))
.where(
and(eq(bookmarkAssets.sourceUrl, url), eq(bookmarks.userId, ctx.user.id)),
);
if (assetResult.length == 0) {
return null;
}
return getBookmark(ctx, assetResult[0].id);
}

async function attemptToDedupLink(ctx: AuthedContext, url: string) {
const result = await ctx.db
.select({
Expand All @@ -133,7 +153,7 @@ async function attemptToDedupLink(ctx: AuthedContext, url: string) {
.where(and(eq(bookmarkLinks.url, url), eq(bookmarks.userId, ctx.user.id)));

if (result.length == 0) {
return null;
return await attemptToDedupLinkWithBookmarkAssets(ctx, url);
}
return getBookmark(ctx, result[0].id);
}
Expand Down
Loading