discourse/app/assets/javascripts/admin/addon/adapters/theme.js
Osama Sayegh e564ab5f63
PERF: Improve performance of the new themes listing page (#32641)
The new themes listing page at `/admin/config/customize/themes`
currently has poor performance compared to the components page
(`/admin/config/customize/components`) due to various N+1 issues,
loading all themes and components from the server when only themes are
needed, and serializing data/attributes that aren't needed for rendering
the themes grid.

This commit improves the performance by eliminating all N+1 that are
currently present, excluding components from the page payload, and
reducing the amount of data transmitted for each theme when loading the
page.
2025-05-08 19:18:07 +03:00

36 lines
828 B
JavaScript
Vendored

import RestAdapter from "discourse/adapters/rest";
export default class Theme extends RestAdapter {
jsonMode = true;
basePath() {
return "/admin/";
}
pathFor(store, type, findArgs) {
if (findArgs?.useConfigAreaEndpoint) {
return "/admin/config/customize/themes";
}
return super.pathFor(...arguments);
}
afterFindAll(results) {
let map = {};
results.forEach((theme) => {
map[theme.id] = theme;
});
results.forEach((theme) => {
let mapped = theme.get("child_themes") || [];
mapped = mapped.map((t) => map[t.id]);
theme.set("childThemes", mapped);
let mappedParents = theme.get("parent_themes") || [];
mappedParents = mappedParents.map((t) => map[t.id]);
theme.set("parentThemes", mappedParents);
});
return results;
}
}