Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: debounce gallery search and handle overlapping pages (#7040)
[._.]/ Adam Eivyf086853d1c7e
diff --git a/client/src/components/loraTraining/ImportGalleryDialog.jsx b/client/src/components/loraTraining/ImportGalleryDialog.jsxindex b9b157b72b..7d5aee55f9 100644--- a/client/src/components/loraTraining/ImportGalleryDialog.jsx+++ b/client/src/components/loraTraining/ImportGalleryDialog.jsx@@ -21,7 +21,7 @@ const MAX_IMPORT = 50;export default function ImportGalleryDialog({ dataset, onClose, onImported }) {const [items, setItems] = useState([]);const [loading, setLoading] = useState(false);- const [total, setTotal] = useState(0);+ const [nextOffset, setNextOffset] = useState(null);const [offset, setOffset] = useState(0);const requestId = useRef(0);const [error, setError] = useState(false);@@ -34,20 +34,26 @@ export default function ImportGalleryDialog({ dataset, onClose, onImported }) {const id = ++requestId.current;setLoading(true);setError(false);- listImageGalleryPage({ limit: 60, offset, q: query, hidden: false }, { silent: true })- .then(page => {- if (id !== requestId.current) return;- const next = page.items.map(normalizeImage);- setItems(prev => offset === 0 ? next : [...prev, ...next]);- setTotal(page.total);- })- .catch(err => {- if (id !== requestId.current) return;- setError(true);- toast.error(err.message || 'Failed to load gallery');- })- .finally(() => { if (id === requestId.current) setLoading(false); });- return () => { requestId.current += 1; };+ const timer = setTimeout(() => {+ listImageGalleryPage({ limit: 60, offset, q: query, hidden: false }, { silent: true })+ .then(page => {+ if (id !== requestId.current) return;+ const next = page.items.map(normalizeImage).filter(item => item.filename);+ setItems(prev => {+ const combined = offset === 0 ? next : [...prev, ...next];+ return [...new Map(combined.map(item => [item.filename, item])).values()];+ });+ const end = offset + page.items.length;+ setNextOffset(page.items.length && end < page.total ? end : null);+ })+ .catch(err => {+ if (id !== requestId.current) return;+ setError(true);+ toast.error(err.message || 'Failed to load gallery');+ })+ .finally(() => { if (id === requestId.current) setLoading(false); });+ }, query ? 250 : 0);+ return () => { clearTimeout(timer); requestId.current += 1; };}, [query, offset, retry]);const toggle = useCallback((filename) => {@@ -92,7 +98,7 @@ export default function ImportGalleryDialog({ dataset, onClose, onImported }) {<inputtype="text"value={query}- onChange={(e) => { setQuery(e.target.value); setOffset(0); setItems([]); setTotal(0); }}+ onChange={(e) => { requestId.current += 1; setQuery(e.target.value); setOffset(0); setItems([]); setNextOffset(null); }}placeholder="Search prompt, model, seed, LoRA…"aria-label="Search gallery images"className="w-full pl-7 pr-7 py-1.5 text-xs bg-port-bg border border-port-border rounded-lg text-white placeholder-gray-500 focus:outline-none focus:border-port-accent"@@ -101,7 +107,7 @@ export default function ImportGalleryDialog({ dataset, onClose, onImported }) {{query && (<buttontype="button"- onClick={() => { setQuery(''); setOffset(0); setItems([]); setTotal(0); }}+ onClick={() => { requestId.current += 1; setQuery(''); setOffset(0); setItems([]); setNextOffset(null); }}className="absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-white"aria-label="Clear search">@@ -147,8 +153,8 @@ export default function ImportGalleryDialog({ dataset, onClose, onImported }) {</div>)}{error && <button type="button" onClick={() => setRetry(n => n + 1)} className="w-full min-h-[44px] text-port-accent">Retry loading images</button>}- {!error && items.length < total && (- <button type="button" disabled={loading} onClick={() => setOffset(items.length)}+ {!error && nextOffset !== null && (+ <button type="button" disabled={loading} onClick={() => setOffset(nextOffset)}className="w-full min-h-[44px] mt-3 text-sm text-port-accent disabled:opacity-50">{loading ? 'Loading…' : 'Show more'}</button>diff --git a/client/src/components/loraTraining/ImportGalleryDialog.test.jsx b/client/src/components/loraTraining/ImportGalleryDialog.test.jsxindex 5f101bd048..f0fc5d414e 100644--- a/client/src/components/loraTraining/ImportGalleryDialog.test.jsx+++ b/client/src/components/loraTraining/ImportGalleryDialog.test.jsx@@ -15,22 +15,30 @@ vi.mock('../ui/Modal', () => ({ default: ({ children }) => <div>{children}</div>describe('gallery import paging', () => {it('pages and searches on the server while retaining selected filenames', async () => {api.listImageGalleryPage.mockImplementation(async ({ offset, q }) => ({- items: [{ filename: q ? 'found.png' : offset ? 'second.png' : 'first.png' }],- total: q ? 1 : 2, limit: 60, offset,+ items: q ? [{ filename: 'found.png' }] : offset === 0 ? [{ filename: 'first.png' }]+ : offset === 1 ? [{ filename: 'first.png' }, { filename: 'second.png' }] : [],+ total: q ? 1 : 4, limit: 60, offset,}));api.importLoraDatasetGalleryImages.mockResolvedValue({ images: [] });- render(<ImportGalleryDialog dataset={{ id: 'dataset' }} />);+ const onImported = vi.fn();+ render(<ImportGalleryDialog dataset={{ id: 'dataset' }} onClose={vi.fn()} onImported={onImported} />);fireEvent.click(await screen.findByText('first.png'));fireEvent.click(screen.getByRole('button', { name: 'Show more' }));await screen.findByText('second.png');+ expect(screen.getAllByText('first.png')).toHaveLength(1);expect(api.listImageGalleryPage).toHaveBeenCalledWith({ limit: 60, offset: 1, q: '', hidden: false }, { silent: true });+ fireEvent.click(screen.getByRole('button', { name: 'Show more' }));+ await waitFor(() => expect(screen.queryByRole('button', { name: 'Show more' })).toBeNull());+ expect(api.listImageGalleryPage).toHaveBeenLastCalledWith(+ { limit: 60, offset: 3, q: '', hidden: false }, { silent: true });fireEvent.change(screen.getByLabelText('Search gallery images'), { target: { value: 'fox' } });await screen.findByText('found.png');expect(screen.queryByText('first.png')).toBeNull();expect(api.listImageGalleryPage).toHaveBeenLastCalledWith({ limit: 60, offset: 0, q: 'fox', hidden: false }, { silent: true });fireEvent.click(screen.getByRole('button', { name: 'Import 1' }));- await waitFor(() => expect(api.importLoraDatasetGalleryImages).toHaveBeenCalledWith('dataset', ['first.png']));+ await waitFor(() => expect(onImported).toHaveBeenCalledWith([]));+ expect(api.importLoraDatasetGalleryImages).toHaveBeenCalledWith('dataset', ['first.png']);});});diff --git a/docs/IMAGE_GALLERY.md b/docs/IMAGE_GALLERY.mdindex 52c8d90eb7..c17b35713b 100644--- a/docs/IMAGE_GALLERY.md+++ b/docs/IMAGE_GALLERY.md@@ -16,6 +16,9 @@ Production pages read the derived PostgreSQL `media_assets` index with SQL LIMITand OFFSET. Ordering is newest first with a stable media-key tie break. Searchmatches all whitespace-separated tokens, case-insensitively, anywhere in themetadata JSON (including prompt and filename); percent and underscore are literal.+This deliberately broadens the old curated-field search: metadata keys, timestamps,+and other stored fields can match too. Search scans metadata inside PostgreSQL;+paging bounds transfer and browser state, not the search scan itself.No request scans sidecars to recover from a database error.Sidecars remain authoritative. Boot reconcile scans disk and repairs index drift.diff --git a/server/services/mediaAssetIndex/gallery.test.js b/server/services/mediaAssetIndex/gallery.test.jsindex 362e7adc1a..6ab46f49e8 100644--- a/server/services/mediaAssetIndex/gallery.test.js+++ b/server/services/mediaAssetIndex/gallery.test.js@@ -1,5 +1,6 @@import { describe, it, expect, vi, afterEach } from 'vitest';import { listGalleryPage } from './gallery.js';+import { imageToRow } from './logic.js';import { query } from '../../lib/db.js';vi.mock('../../lib/db.js', () => ({ query: vi.fn() }));@@ -10,9 +11,9 @@ describe('indexed gallery page', () => {vi.stubEnv('NODE_ENV', 'production');vi.stubEnv('VITEST', undefined);vi.stubEnv('MEMORY_BACKEND', 'db');- const item = { filename: 'fox.png', path: '/data/images/fox.png', prompt: '100% fox', seed: 8 };+ const item = { filename: 'fox.png', path: '/data/images/fox.png', prompt: '100% fox', seed: 8, hidden: false, loraNames: ['portrait'] };query.mockImplementation(async sql => sql.includes('COUNT(*)')- ? { rows: [{ count: '27' }] } : { rows: [{ data: item }] });+ ? { rows: [{ count: '27' }] } : { rows: [imageToRow(item)] });const disk = vi.fn();expect(await listGalleryPage({ limit: 5, offset: 10, q: '100% fox', hidden: false }, disk)).toEqual({ items: [item], total: 27, limit: 5, offset: 10 });