A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
fix: Incremental polling interval for ongoing crawls
Mohamed Bassem18c1d15e84b6
diff --git a/apps/mobile/components/bookmarks/BookmarkCard.tsx b/apps/mobile/components/bookmarks/BookmarkCard.tsxindex e4c2eee8..62e74e97 100644--- a/apps/mobile/components/bookmarks/BookmarkCard.tsx+++ b/apps/mobile/components/bookmarks/BookmarkCard.tsx@@ -28,7 +28,7 @@ import {import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";import {getBookmarkLinkImageUrl,- isBookmarkStillLoading,+ getBookmarkRefreshInterval,isBookmarkStillTagging,} from "@karakeep/shared/utils/bookmarkUtils";@@ -432,11 +432,7 @@ export default function BookmarkCard({if (!data) {return false;}- // If the link is not crawled or not tagged- if (isBookmarkStillLoading(data)) {- return 1000;- }- return false;+ return getBookmarkRefreshInterval(data);},},);diff --git a/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkCard.tsxindex 4fc7d94a..595a9e00 100644--- a/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx+++ b/apps/web/components/dashboard/bookmarks/BookmarkCard.tsx@@ -1,7 +1,7 @@import { api } from "@/lib/trpc";import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks";-import { isBookmarkStillLoading } from "@karakeep/shared/utils/bookmarkUtils";+import { getBookmarkRefreshInterval } from "@karakeep/shared/utils/bookmarkUtils";import AssetCard from "./AssetCard";import LinkCard from "./LinkCard";@@ -26,10 +26,7 @@ export default function BookmarkCard({if (!data) {return false;}- if (isBookmarkStillLoading(data)) {- return 1000;- }- return false;+ return getBookmarkRefreshInterval(data);},},);diff --git a/apps/web/components/dashboard/preview/BookmarkPreview.tsx b/apps/web/components/dashboard/preview/BookmarkPreview.tsxindex 01c86f6e..4766bd32 100644--- a/apps/web/components/dashboard/preview/BookmarkPreview.tsx+++ b/apps/web/components/dashboard/preview/BookmarkPreview.tsx@@ -20,10 +20,10 @@ import { Building, CalendarDays, ExternalLink, User } from "lucide-react";import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks";import {+ getBookmarkRefreshInterval,getBookmarkTitle,getSourceUrl,isBookmarkStillCrawling,- isBookmarkStillLoading,} from "@karakeep/shared/utils/bookmarkUtils";import SummarizeBookmarkArea from "../bookmarks/SummarizeBookmarkArea";@@ -129,11 +129,7 @@ export default function BookmarkPreview({if (!data) {return false;}- // If the link is not crawled or not tagged- if (isBookmarkStillLoading(data)) {- return 1000;- }- return false;+ return getBookmarkRefreshInterval(data);},},);diff --git a/packages/shared-react/hooks/bookmarks.ts b/packages/shared-react/hooks/bookmarks.tsindex 15b678cc..c4f0c8e7 100644--- a/packages/shared-react/hooks/bookmarks.ts+++ b/packages/shared-react/hooks/bookmarks.ts@@ -1,4 +1,4 @@-import { isBookmarkStillLoading } from "@karakeep/shared/utils/bookmarkUtils";+import { getBookmarkRefreshInterval } from "@karakeep/shared/utils/bookmarkUtils";import { api } from "../trpc";import { useBookmarkGridContext } from "./bookmark-grid-context";@@ -13,11 +13,7 @@ export function useAutoRefreshingBookmarkQuery(if (!data) {return false;}- // If the link is not crawled or not tagged- if (isBookmarkStillLoading(data)) {- return 1000;- }- return false;+ return getBookmarkRefreshInterval(data);},});}diff --git a/packages/shared/utils/bookmarkUtils.ts b/packages/shared/utils/bookmarkUtils.tsindex 97ef08fc..9d4659b1 100644--- a/packages/shared/utils/bookmarkUtils.ts+++ b/packages/shared/utils/bookmarkUtils.ts@@ -1,8 +1,6 @@import { BookmarkTypes, ZBookmark, ZBookmarkedLink } from "../types/bookmarks";import { getAssetUrl } from "./assetUtils";-const MAX_LOADING_MSEC = 30 * 1000;-export function getBookmarkLinkAssetIdOrUrl(bookmark: ZBookmarkedLink) {if (bookmark.imageAssetId) {return { assetId: bookmark.imageAssetId, localAsset: true as const };@@ -31,24 +29,16 @@ export function getBookmarkLinkImageUrl(bookmark: ZBookmarkedLink) {export function isBookmarkStillCrawling(bookmark: ZBookmark) {return (- bookmark.content.type == BookmarkTypes.LINK &&- !bookmark.content.crawledAt &&- Date.now().valueOf() - bookmark.createdAt.valueOf() < MAX_LOADING_MSEC+ bookmark.content.type == BookmarkTypes.LINK && !bookmark.content.crawledAt);}export function isBookmarkStillTagging(bookmark: ZBookmark) {- return (- bookmark.taggingStatus == "pending" &&- Date.now().valueOf() - bookmark.createdAt.valueOf() < MAX_LOADING_MSEC- );+ return bookmark.taggingStatus == "pending";}export function isBookmarkStillSummarizing(bookmark: ZBookmark) {- return (- bookmark.summarizationStatus == "pending" &&- Date.now().valueOf() - bookmark.createdAt.valueOf() < MAX_LOADING_MSEC- );+ return bookmark.summarizationStatus == "pending";}export function isBookmarkStillLoading(bookmark: ZBookmark) {@@ -59,6 +49,35 @@ export function isBookmarkStillLoading(bookmark: ZBookmark) {);}+export function getBookmarkRefreshInterval(+ bookmark: ZBookmark,+): number | false {+ if (!isBookmarkStillLoading(bookmark)) {+ return false;+ }++ // For the first 30 seconds, we'll refresh the bookmark every second+ if (Date.now().valueOf() - bookmark.createdAt.valueOf() < 30 * 1000) {+ return 1000;+ }++ // Then, we'll refresh it every 10 seconds after than for 10mins+ if (Date.now().valueOf() - bookmark.createdAt.valueOf() < 10 * 60 * 1000) {+ return 10_000;+ }++ // Then, we'll refresh it every minute after than for 6hrs+ if (+ Date.now().valueOf() - bookmark.createdAt.valueOf() <+ 6 * 60 * 60 * 1000+ ) {+ return 60_000;+ }++ // Then we'll stop refreshing it+ return false;+}+export function getSourceUrl(bookmark: ZBookmark) {if (bookmark.content.type === BookmarkTypes.LINK) {return bookmark.content.url;