fix: address performance and security findings
- Add PostgreSQL-backed backend and frontend tests to CI - Harden Android API logging and disable app backups - Update the performance report with resolved findings
This commit is contained in:
1 parent
a84a36349b
commit
937f51b4fb
35 files changed
+2566
-332
No files matched your search
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import ListCard from './ListCard.svelte';
|
||||
|
||||
let { lists, fields, items, onSelect } = $props();
|
||||
let { lists, fieldsByList, itemsByList, onSelect } = $props();
|
||||
</script>
|
||||
|
||||
{#if lists.length === 0}
|
||||
@@ -12,7 +12,12 @@
|
||||
{:else}
|
||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{#each lists as list (list.id)}
|
||||
<ListCard {list} {fields} {items} onClick={onSelect} />
|
||||
<ListCard
|
||||
{list}
|
||||
fields={fieldsByList.get(list.id) ?? []}
|
||||
items={itemsByList.get(list.id) ?? []}
|
||||
onClick={onSelect}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import ListRow from './ListRow.svelte';
|
||||
|
||||
let { lists, fields, items, onSelect } = $props();
|
||||
let { lists, fieldsByList, itemsByList, onSelect } = $props();
|
||||
</script>
|
||||
|
||||
<table class="w-full text-left text-sm">
|
||||
@@ -15,7 +15,12 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each lists as list (list.id)}
|
||||
<ListRow {list} {fields} {items} onClick={onSelect} />
|
||||
<ListRow
|
||||
{list}
|
||||
fields={fieldsByList.get(list.id) ?? []}
|
||||
items={itemsByList.get(list.id) ?? []}
|
||||
onClick={onSelect}
|
||||
/>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -6,8 +6,20 @@ export function listItemsFor(items, listId) {
|
||||
return items.filter((i) => i.listId === listId && !i.isDeleted);
|
||||
}
|
||||
|
||||
export function itemValuesFor(values, itemId) {
|
||||
return values.filter((v) => v.itemId === itemId);
|
||||
// groupByKey indexes rows by keyOf in one pass. Build it once per data change in a
|
||||
// $derived, then look rows up per card, row or cell instead of rescanning the data.
|
||||
export function groupByKey(rows, keyOf) {
|
||||
const groups = new Map();
|
||||
for (const row of rows) {
|
||||
const key = keyOf(row);
|
||||
const group = groups.get(key);
|
||||
if (group) {
|
||||
group.push(row);
|
||||
} else {
|
||||
groups.set(key, [row]);
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
export function valueFor(values, itemId, fieldId) {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
|
||||
import { fmtDate, groupByKey, listFieldsFor, listItemsFor, valueFor } from './listHelpers.js';
|
||||
|
||||
test('listFieldsFor keeps the list’s live fields in display order', () => {
|
||||
const fields = [
|
||||
{ id: 'c', listId: 'l1', order: 2 },
|
||||
{ id: 'gone', listId: 'l1', order: 0, isDeleted: true },
|
||||
{ id: 'other', listId: 'l2', order: 0 },
|
||||
{ id: 'a', listId: 'l1', order: 0 },
|
||||
{ id: 'unordered', listId: 'l1' },
|
||||
{ id: 'b', listId: 'l1', order: 1 },
|
||||
];
|
||||
|
||||
const ids = listFieldsFor(fields, 'l1').map((f) => f.id);
|
||||
|
||||
// A field without an order sorts as 0, and the sort is stable.
|
||||
assert.deepEqual(ids, ['a', 'unordered', 'b', 'c']);
|
||||
});
|
||||
|
||||
test('listFieldsFor does not reorder the array it was given', () => {
|
||||
const fields = [
|
||||
{ id: 'b', listId: 'l1', order: 1 },
|
||||
{ id: 'a', listId: 'l1', order: 0 },
|
||||
];
|
||||
listFieldsFor(fields, 'l1');
|
||||
assert.deepEqual(
|
||||
fields.map((f) => f.id),
|
||||
['b', 'a'],
|
||||
);
|
||||
});
|
||||
|
||||
test('listItemsFor keeps only the list’s live items', () => {
|
||||
const items = [
|
||||
{ id: 'i1', listId: 'l1' },
|
||||
{ id: 'i2', listId: 'l1', isDeleted: true },
|
||||
{ id: 'i3', listId: 'l2' },
|
||||
];
|
||||
assert.deepEqual(
|
||||
listItemsFor(items, 'l1').map((i) => i.id),
|
||||
['i1'],
|
||||
);
|
||||
assert.deepEqual(listItemsFor(items, 'missing'), []);
|
||||
});
|
||||
|
||||
test('groupByKey indexes rows by key and keeps their order', () => {
|
||||
const rows = [
|
||||
{ id: 1, listId: 'a' },
|
||||
{ id: 2, listId: 'b' },
|
||||
{ id: 3, listId: 'a' },
|
||||
];
|
||||
|
||||
const groups = groupByKey(rows, (row) => row.listId);
|
||||
|
||||
assert.deepEqual([...groups.keys()], ['a', 'b']);
|
||||
assert.deepEqual(
|
||||
groups.get('a').map((row) => row.id),
|
||||
[1, 3],
|
||||
);
|
||||
assert.equal(groups.get('missing'), undefined);
|
||||
assert.equal(groupByKey([], (row) => row.listId).size, 0);
|
||||
});
|
||||
|
||||
test('valueFor finds the value in one cell, or null', () => {
|
||||
const values = [
|
||||
{ itemId: 'i1', fieldId: 'f1', value: 'milk' },
|
||||
{ itemId: 'i1', fieldId: 'f2', value: '' },
|
||||
{ itemId: 'i2', fieldId: 'f1', value: 'eggs' },
|
||||
];
|
||||
|
||||
assert.equal(valueFor(values, 'i1', 'f1'), 'milk');
|
||||
assert.equal(valueFor(values, 'i2', 'f1'), 'eggs');
|
||||
// An empty value is a value, not a missing one.
|
||||
assert.equal(valueFor(values, 'i1', 'f2'), '');
|
||||
assert.equal(valueFor(values, 'i2', 'f2'), null);
|
||||
});
|
||||
|
||||
test('fmtDate shows a dash for missing or invalid dates', () => {
|
||||
assert.equal(fmtDate(null), '—');
|
||||
assert.equal(fmtDate(undefined), '—');
|
||||
assert.equal(fmtDate('not a date'), '—');
|
||||
});
|
||||
|
||||
test('fmtDate formats a millisecond timestamp for the reader’s locale', () => {
|
||||
const ms = 1_700_000_000_000;
|
||||
assert.equal(fmtDate(ms), new Date(ms).toLocaleString());
|
||||
assert.notEqual(fmtDate(ms), '—');
|
||||
});
|
||||
@@ -3,6 +3,7 @@
|
||||
import { resolve } from '$app/paths';
|
||||
import { ArrowDown, ArrowUp, LayoutGrid, List, Search, X } from '@lucide/svelte';
|
||||
import { createOverviewData } from '$lib/features/lists/listsData.svelte.js';
|
||||
import { groupByKey } from '$lib/features/lists/listHelpers.js';
|
||||
import { searchState, filterListsBySearch } from '$lib/search.svelte.js';
|
||||
import { createDashboardViewMode } from '$lib/preferences/viewMode.svelte.js';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
@@ -42,6 +43,10 @@
|
||||
let searched = $derived(filterListsBySearch(overview.lists, searchState.query));
|
||||
let sorted = $derived(sortLists(searched, sortField, sortDir));
|
||||
let pageItems = $derived(sorted.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize));
|
||||
// Index fields and items by list once per data change, so each visible card or row
|
||||
// reads its own slice instead of scanning every field and item.
|
||||
let fieldsByList = $derived(groupByKey(overview.fields, (f) => f.listId));
|
||||
let itemsByList = $derived(groupByKey(overview.items, (i) => i.listId));
|
||||
|
||||
$effect(() => {
|
||||
void searchState.query;
|
||||
@@ -148,9 +153,9 @@
|
||||
|
||||
<div class="overflow-x-auto rounded-lg border border-border bg-bg p-3">
|
||||
{#if viewMode.mode === 'list'}
|
||||
<ListsTable lists={pageItems} fields={overview.fields} items={overview.items} onSelect={goToList} />
|
||||
<ListsTable lists={pageItems} {fieldsByList} {itemsByList} onSelect={goToList} />
|
||||
{:else}
|
||||
<ListsGrid lists={pageItems} fields={overview.fields} items={overview.items} onSelect={goToList} />
|
||||
<ListsGrid lists={pageItems} {fieldsByList} {itemsByList} onSelect={goToList} />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import { Pagination } from '@gabriel20xx/web-ui';
|
||||
import { createOverviewData } from '$lib/features/lists/listsData.svelte.js';
|
||||
import { listFieldsFor, listItemsFor, itemValuesFor, valueFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||
import { listFieldsFor, listItemsFor, groupByKey, valueFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||
|
||||
let { data } = $props();
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
const list = $derived(overview.lists.find((l) => l.id === data.id));
|
||||
const listFields = $derived(listFieldsFor(overview.fields, data.id));
|
||||
const listItems = $derived(listItemsFor(overview.items, data.id));
|
||||
const valuesByItem = $derived(groupByKey(overview.values, (v) => v.itemId));
|
||||
|
||||
let page = $state(1);
|
||||
let pageSize = $state(24);
|
||||
@@ -91,7 +92,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each pageItems as item (item.id)}
|
||||
{@const itemValues = itemValuesFor(overview.values, item.id)}
|
||||
{@const itemValues = valuesByItem.get(item.id) ?? []}
|
||||
<tr class="border-t border-border">
|
||||
<td class="py-2 pl-3 font-mono text-xs text-muted-fg">{item.id.slice(0, 8)}…</td>
|
||||
{#each listFields as f (f.id)}
|
||||
|
||||
Reference in new issue
Block a user