feature (tag): tag caching

This commit is contained in:
MickaelK 2025-08-07 23:55:52 +10:00
parent 8ff5b47f06
commit 6eeddd42c3
2 changed files with 57 additions and 42 deletions

View file

@ -15,6 +15,7 @@ import { extractPath, isDir, isNativeFileUpload } from "../pages/filespage/helpe
import { mv as mvVL, withVirtualLayer } from "../pages/filespage/model_virtual_layer.js";
import { getCurrentPath } from "../pages/viewerpage/common.js";
import { generateSkeleton } from "./skeleton.js";
import { onLogout } from "../pages/ctrl_logout.js";
const state = { scrollTop: 0, $cache: null };
const mv = (from, to) => withVirtualLayer(
@ -257,6 +258,8 @@ async function _createListOfFiles(path, currentName, dirpath) {
return $ul;
}
let tagcache = null;
onLogout(() => tagcache = null);
async function ctrlTagPane(render) {
if (!getConfig("enable_tags", false)) return;
render(createElement(`<div>${generateSkeleton(2)}</div>`));
@ -272,7 +275,11 @@ async function ctrlTagPane(render) {
</ul>
</div>
`);
const tags = await ajax({
render($page);
effect(rxjs.merge(
rxjs.of(tagcache).pipe(rxjs.filter((cache) => cache)),
ajax({
url: forwardURLParams(`api/metadata/search`, ["share"]),
method: "POST",
responseType: "json",
@ -287,14 +294,15 @@ async function ctrlTagPane(render) {
.map(({ name }) => name)
.sort()
),
rxjs.tap((tags) => tagcache = tags),
rxjs.catchError(() => rxjs.of([])),
).toPromise();
),
).pipe(rxjs.tap((tags) => {
if (tags.length === 0) {
render(createElement("<div></div>"));
$page.classList.add("hidden");
return;
}
render($page);
$page.classList.remove("hidden");
const $fragment = document.createDocumentFragment();
tags.forEach((name) => {
const $tag = createElement(`
@ -316,7 +324,8 @@ async function ctrlTagPane(render) {
}
$fragment.appendChild($tag);
});
qs($page, `[data-bind="taglist"]`).appendChild($fragment);
qs($page, `[data-bind="taglist"]`).replaceChildren($fragment);
})));
}
export function init() {

View file

@ -12,7 +12,13 @@ export default function(render) {
effect(deleteSession().pipe(
rxjs.mergeMap(setup_config),
rxjs.tap(() => { while (hooks.length) hooks.pop()(); }),
rxjs.tap(() => getConfig("logout") ? location.href = getConfig("logout") : navigate(toHref("/"))),
rxjs.catchError(ctrlError(render)),
));
}
const hooks = [];
export function onLogout(fn) {
hooks.push(fn);
}