fix: limits for imports and status checks, the dashboard switch in settings scrolls
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:
@@ -181,6 +181,8 @@ export const getStatuses = createServerFn({ method: "GET" })
|
||||
.where(
|
||||
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)))
|
||||
return Object.fromEntries(links.map((l, i) => [l.id, up[i]]))
|
||||
})
|
||||
|
||||
@@ -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("javascript:alert(1)")).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", () => {
|
||||
|
||||
+11
-1
@@ -4,6 +4,7 @@ import { z } from "zod"
|
||||
const httpUrl = z.url({ protocol: /^https?$/ }).max(2000)
|
||||
const MAX_CARDS = 100
|
||||
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.
|
||||
@@ -37,7 +38,13 @@ export const backupSchema = z.object({
|
||||
})
|
||||
)
|
||||
.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>
|
||||
|
||||
@@ -76,6 +83,7 @@ export function parseBookmarks(html: string) {
|
||||
const folders: string[] = [] // the path to where we are
|
||||
let heading: string | null = null // a folder name that waits for its <DL>
|
||||
let skipped = 0
|
||||
let total = 0
|
||||
const tags =
|
||||
/<DL\b|<\/DL>|<H3\b[^>]*>([\s\S]*?)<\/H3>|<A\b([^>]*)>([\s\S]*?)<\/A>/gi
|
||||
for (const [tag, folder, attributes, title] of html.matchAll(tags)) {
|
||||
@@ -95,6 +103,7 @@ export function parseBookmarks(html: string) {
|
||||
}
|
||||
if (
|
||||
!url.success ||
|
||||
total >= MAX_TOTAL ||
|
||||
card.links.length >= MAX_LINKS ||
|
||||
(!cards.has(path) && cards.size >= MAX_CARDS)
|
||||
) {
|
||||
@@ -102,6 +111,7 @@ export function parseBookmarks(html: string) {
|
||||
continue
|
||||
}
|
||||
cards.set(path, card)
|
||||
total++
|
||||
card.links.push({
|
||||
name: (text(title) || new URL(url.data).hostname).slice(0, 60),
|
||||
url: url.data,
|
||||
|
||||
@@ -565,6 +565,8 @@ function Settings() {
|
||||
<SegmentedControl
|
||||
aria-labelledby="settings-wallpaper-of"
|
||||
size="md"
|
||||
// many dashboards on a narrow screen: scroll, not overflow
|
||||
className="max-w-full overflow-x-auto"
|
||||
value={data.dashboardId}
|
||||
onValueChange={(d) =>
|
||||
router.navigate({
|
||||
|
||||
Reference in New Issue
Block a user