Perf: 9 Performance-Fixes — SW by-v1072
Backend: - DB: 3 neue Indizes (forum_posts thread+user, routes user) — Forum/Routen-Queries - Caching: cache.py (TTL-Cache ohne neue Dependency) für 5 statische Listen (training_exercises, pflege_tipps, wiki_stats, wiki_gruppen, help_articles) - diary.py + breeder_photos.py: Bildverarbeitung (ffmpeg/PIL/EXIF) per run_in_executor → blockiert Event-Loop nicht mehr - scheduler.py: 11 kollidierende Jobs auf 5-Min-Intervalle gestaggert, coalesce=True - social.py: ORDER BY RANDOM() ohne LIMIT in 2 Stellen gefixt - alerts.py: Haversine-Loop bekommt SQL-Bounding-Box-Vorfilter Frontend: - sw.js: Tile-Cache mit LRU-Eviction (max 500 Einträge) - admin.js: Event-Listener-Leak — Tab-Klicks per Delegation statt N Listener - api.js: compressImage() Helper — Client-seitiges Resize auf max 2000px (HEIC/Videos/<500KB unverändert), integriert in 8 Upload-Stellen (diary, dog-profile×2, walks, poison, lost, health×2) Bump APP_VER 1071 → 1072 (sw.js, app.js, main.py, index.html)
This commit is contained in:
parent
3abf974d29
commit
c03884cb81
23 changed files with 461 additions and 120 deletions
|
|
@ -8,6 +8,7 @@ window.Page_admin = (() => {
|
|||
let _container = null;
|
||||
let _appState = null;
|
||||
let _tab = 'uebersicht';
|
||||
let _delegationAttached = null; // WeakRef-Ersatz: zuletzt mit Delegation versehener Container
|
||||
|
||||
const TABS = [
|
||||
{ id: 'uebersicht', label: 'Übersicht', icon: 'house-line' },
|
||||
|
|
@ -71,20 +72,43 @@ window.Page_admin = (() => {
|
|||
|
||||
_container.querySelector('#adm-tabs')
|
||||
?.style.setProperty('--adm-tab-cols', Math.ceil(TABS.length / 2));
|
||||
_container.querySelectorAll('#adm-tabs .by-tab').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
_tab = btn.dataset.tab;
|
||||
_container.querySelectorAll('#adm-tabs .by-tab').forEach(b =>
|
||||
b.classList.toggle('active', b.dataset.tab === _tab)
|
||||
);
|
||||
_renderTab();
|
||||
});
|
||||
});
|
||||
|
||||
// Event-Delegation: Listener EINMAL pro Container-Instanz setzen
|
||||
// (innerHTML überschreibt zwar das DOM, aber bei jedem init() würden ohne
|
||||
// Flag erneut N=18 Tab-Listener akkumuliert werden)
|
||||
if (_delegationAttached !== _container) {
|
||||
_container.addEventListener('click', _onContainerClick);
|
||||
_delegationAttached = _container;
|
||||
}
|
||||
|
||||
_renderActionItems();
|
||||
_renderTab();
|
||||
}
|
||||
|
||||
// Delegation-Handler für Tab-Buttons + Action-Item-Buttons
|
||||
function _onContainerClick(e) {
|
||||
// Tab-Button (#adm-tabs .by-tab)
|
||||
const tabBtn = e.target.closest('#adm-tabs .by-tab');
|
||||
if (tabBtn && _container.contains(tabBtn)) {
|
||||
_tab = tabBtn.dataset.tab;
|
||||
_container.querySelectorAll('#adm-tabs .by-tab').forEach(b =>
|
||||
b.classList.toggle('active', b.dataset.tab === _tab)
|
||||
);
|
||||
_renderTab();
|
||||
return;
|
||||
}
|
||||
// Action-Item-Button ([data-action-tab])
|
||||
const actionBtn = e.target.closest('[data-action-tab]');
|
||||
if (actionBtn && _container.contains(actionBtn)) {
|
||||
_tab = actionBtn.dataset.actionTab;
|
||||
_container.querySelectorAll('#adm-tabs .by-tab').forEach(b =>
|
||||
b.classList.toggle('active', b.dataset.tab === _tab)
|
||||
);
|
||||
_renderTab();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async function _renderActionItems() {
|
||||
const el = _container.querySelector('#adm-action-items');
|
||||
if (!el) return;
|
||||
|
|
@ -134,15 +158,7 @@ window.Page_admin = (() => {
|
|||
</span>
|
||||
</div>`;
|
||||
|
||||
el.querySelectorAll('[data-action-tab]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
_tab = btn.dataset.actionTab;
|
||||
_container.querySelectorAll('#adm-tabs .by-tab').forEach(b =>
|
||||
b.classList.toggle('active', b.dataset.tab === _tab)
|
||||
);
|
||||
_renderTab();
|
||||
});
|
||||
});
|
||||
// Klicks auf [data-action-tab] werden zentral via _onContainerClick (Delegation) behandelt
|
||||
}
|
||||
|
||||
async function _renderTab() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue