fix: limits for imports and status checks, the dashboard switch in settings scrolls
images / check (push) Successful in 27s
images / image (push) Successful in 20s

One import holds 5000 links at most, since it is one transaction. One
status request checks 200 links at most. With many dashboards the switch
in Settings, Wallpaper was wider than a phone.
This commit is contained in:
Niklas Haiden
2026-11-21 19:26:45 +01:00
parent 51b52abb15
commit e31d787769
4 changed files with 25 additions and 1 deletions
+2
View File
@@ -181,6 +181,8 @@ export const getStatuses = createServerFn({ method: "GET" })
.where( .where(
and(eq(link.userId, user.id), eq(card.dashboardId, data.dashboardId)) and(eq(link.userId, user.id), eq(card.dashboardId, data.dashboardId))
) )
// one request must not make the server call thousands of addresses
.limit(200)
const up = await Promise.all(links.map((l) => isReachable(l.url))) const up = await Promise.all(links.map((l) => isReachable(l.url)))
return Object.fromEntries(links.map((l, i) => [l.id, up[i]])) return Object.fromEntries(links.map((l, i) => [l.id, up[i]]))
}) })
+10
View File
@@ -86,6 +86,16 @@ test("backupSchema refuses what is not a web address", () => {
assert.ok(backupSchema.safeParse(withUrl("https://example.com")).success) assert.ok(backupSchema.safeParse(withUrl("https://example.com")).success)
assert.ok(!backupSchema.safeParse(withUrl("javascript:alert(1)")).success) assert.ok(!backupSchema.safeParse(withUrl("javascript:alert(1)")).success)
assert.ok(!backupSchema.safeParse({ dashboards: [] }).success) assert.ok(!backupSchema.safeParse({ dashboards: [] }).success)
// 11 cards with 500 links each are more than one file may hold
const links = Array.from({ length: 500 }, () => ({
name: "L",
url: "https://example.com",
}))
const cards = (n: number) =>
Array.from({ length: n }, () => ({ name: "C", links }))
const file = (n: number) => ({ dashboards: [{ name: "D", cards: cards(n) }] })
assert.ok(backupSchema.safeParse(file(10)).success)
assert.ok(!backupSchema.safeParse(file(11)).success)
}) })
test("portable: uploads stay with their account", () => { test("portable: uploads stay with their account", () => {
+11 -1
View File
@@ -4,6 +4,7 @@ import { z } from "zod"
const httpUrl = z.url({ protocol: /^https?$/ }).max(2000) const httpUrl = z.url({ protocol: /^https?$/ }).max(2000)
const MAX_CARDS = 100 const MAX_CARDS = 100
const MAX_LINKS = 500 // per card const MAX_LINKS = 500 // per card
const MAX_TOTAL = 5000 // links in one file
/** /**
* What an export holds and an import takes: dashboards with their cards and links. * What an export holds and an import takes: dashboards with their cards and links.
@@ -37,7 +38,13 @@ export const backupSchema = z.object({
}) })
) )
.min(1) .min(1)
.max(20), .max(20)
// one import is one transaction: keep it small enough for that
.refine(
(dashboards) =>
dashboards.flatMap((d) => d.cards.flatMap((c) => c.links)).length <=
MAX_TOTAL
),
}) })
export type Backup = z.infer<typeof backupSchema> export type Backup = z.infer<typeof backupSchema>
@@ -76,6 +83,7 @@ export function parseBookmarks(html: string) {
const folders: string[] = [] // the path to where we are const folders: string[] = [] // the path to where we are
let heading: string | null = null // a folder name that waits for its <DL> let heading: string | null = null // a folder name that waits for its <DL>
let skipped = 0 let skipped = 0
let total = 0
const tags = const tags =
/<DL\b|<\/DL>|<H3\b[^>]*>([\s\S]*?)<\/H3>|<A\b([^>]*)>([\s\S]*?)<\/A>/gi /<DL\b|<\/DL>|<H3\b[^>]*>([\s\S]*?)<\/H3>|<A\b([^>]*)>([\s\S]*?)<\/A>/gi
for (const [tag, folder, attributes, title] of html.matchAll(tags)) { for (const [tag, folder, attributes, title] of html.matchAll(tags)) {
@@ -95,6 +103,7 @@ export function parseBookmarks(html: string) {
} }
if ( if (
!url.success || !url.success ||
total >= MAX_TOTAL ||
card.links.length >= MAX_LINKS || card.links.length >= MAX_LINKS ||
(!cards.has(path) && cards.size >= MAX_CARDS) (!cards.has(path) && cards.size >= MAX_CARDS)
) { ) {
@@ -102,6 +111,7 @@ export function parseBookmarks(html: string) {
continue continue
} }
cards.set(path, card) cards.set(path, card)
total++
card.links.push({ card.links.push({
name: (text(title) || new URL(url.data).hostname).slice(0, 60), name: (text(title) || new URL(url.data).hostname).slice(0, 60),
url: url.data, url: url.data,
+2
View File
@@ -565,6 +565,8 @@ function Settings() {
<SegmentedControl <SegmentedControl
aria-labelledby="settings-wallpaper-of" aria-labelledby="settings-wallpaper-of"
size="md" size="md"
// many dashboards on a narrow screen: scroll, not overflow
className="max-w-full overflow-x-auto"
value={data.dashboardId} value={data.dashboardId}
onValueChange={(d) => onValueChange={(d) =>
router.navigate({ router.navigate({