Defer compactSourceSql JSONB projection until after LIMIT/OFFSET in listMixedGalleryPage
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, postgresql
Direzione di ricerca
Start in server/services/mediaAssetIndex/db.js, reading assetSource and listMixedGalleryPage, plus compactSourceSql where the JSONB projection is defined. Check how gallery_assets is materialized and how gallery_page applies LIMIT and OFFSET. Done means compactSourceSql and the full data fetch run only on the bounded page rows, with identical results, verified by db.test.js and db.db.test.js.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Audit slice: server/services/mediaAssetIndex (re-verification of 2026-11-24 performance-efficiency slice) — Date: 2026-11-26
Scope: small
Problem
In server/services/mediaAssetIndex/db.js:249-264 (assetSource) and :319-357 (listMixedGalleryPage), the gallery_assets CTE is declared AS MATERIALIZED and evaluates CASE WHEN kind = 'image' THEN ${compactSourceSql('data')} ELSE data END AS data for every matching image row in media_assets before gallery_page applies ORDER BY ... LIMIT $limit OFFSET $offset:
compactSourceSql()(db.js:189-196) runs a correlatedSELECT jsonb_object_agg(...) || jsonb_strip_nulls(...) FROM jsonb_each(data)with regex matching (~) over the row's full JSONB payload.- Although
#18631moved search and facet predicates onto stored generated columns (search_text,is_hidden,universe_id,entry_category,entry_kind), placingcompactSourceSql('data')inside theMATERIALIZEDgallery_assetsCTE forces PostgreSQL to read/decompressmedia_assets.data(including TOASTed JSONB) and runjsonb_each/jsonb_object_agg/regex for every matching image in the entire gallery, even though the fourCOUNT(*) FILTER (...)aggregates never readdataand onlylimitrows (default 60) ever entergallery_page.
Impact
Every mixed Media Gallery page load (listMixedGalleryPage, invoked by listGalleryPage in server/services/mediaAssetIndex/gallery.js:155) pays O(total_images) JSONB decompression and per-key aggregation work in PostgreSQL instead of O(limit) (60 rows), causing latency and CPU load to scale linearly with total library size even on paginated reads.
Fix
Update server/services/mediaAssetIndex/db.js (and verify with server/services/mediaAssetIndex/db.test.js and server/services/mediaAssetIndex/db.db.test.js):
- Keep
filenameandcleanedFrompredicates at the source level inlistMixedGalleryPage(they are identical acrosstotalFilter,hiddenFilter,facetFilter, andpageFilter), and computehas_cover(kind = 'image' OR NULLIF(video.data->>'thumbnail', '') IS NOT NULL) as a boolean column ingallery_assetssogallery_assetsnever needsmedia_assets.data. - Materialize only
(media_key, kind, ref, created_at, is_hidden, has_cover, video_data)ingallery_assets(withNULL::jsonbfor image rows'video_data, since videos are already compact in the bound parameter). - In the final
SELECTovergallery_page(at mostlimitrows),LEFT JOIN media_assets ma ON ma.media_key = gallery_page.media_key AND gallery_page.kind = 'image'and projectCASE WHEN gallery_page.kind = 'image' THEN ${compact ? compactSourceSql('ma.data') : 'ma.data'} ELSE gallery_page.video_data ENDonly for the bounded page rows.
Acceptance Criteria
-
listMixedGalleryPageno longer evaluatescompactSourceSql('data')or materializesmedia_assets.datainside thegallery_assetsCTE. -
compactSourceSql(and fullma.datafetch for images) executes only on the boundedgallery_page(LIMIT/OFFSET) rows via PK join onmedia_assets.media_key. - All filters (
q,hidden,kind,filename,cleanedFrom,mediaKeys,excludeKeys,cover,universeId,entryCategory,entryKind,orderedKeys,countMediaKeys,compact) return identical items, totals,hiddenTotal, andcounts. - Unit and DB tests (
server/services/mediaAssetIndex/db.test.jsandserver/services/mediaAssetIndex/db.db.test.js) pass, including an assertion thatcompactSourceSqlis applied afterLIMIT/OFFSETrather than insidegallery_assets.
- Lingua principale
- JavaScript
- Stelle
- 38
- Fork
- 32
- Merge medio
- 14m
- PR unite (30g)
- 995
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di atomantic/PortOS
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
effort:low model:light performance performance-efficiency plan planner:gemini-4-neon source:performance-efficiency
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Eliminate O(N×L) live-metadata JSON.stringify and sequential full-archive scans in cosAgentStorageApertaarea:cos-agents effort:medium model:medium performance performance-efficiency plan planner:gemini-4-neon source:performance-efficiency
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
data-integrity-safety data-safety effort:low model:light plan planner:gemini-4-neon source:data-integrity-safety
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
I maintainer di solito rispondono entro 1 giorno
-
bug effort:low model:light plan planner:gemini-4-neon source:ui-runtime-bugs ui-runtime-bugs
Difficoltà 3/5 Mezza giornata Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di atomantic/PortOS
Issue simili
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Agent360dk/browser-mcp#124 ·
I maintainer di solito rispondono entro 2 giorni
-
area:site feature good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
pacocartones/free-llm-api-hub#829 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
Jason-Vaughan/TangleClaw#3270 ·
I maintainer di solito rispondono entro 1 giorno
-
Range with start greater than end crashes the server process (bytes=100-50)Forse già presa @draarivpatel-ui l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100