added cache system

This commit is contained in:
2026-02-12 22:22:53 +01:00
parent 991569d9eb
commit a7ef46640d
7 changed files with 120 additions and 229 deletions

View File

@@ -82,15 +82,14 @@ async function loadOffices() {
if (currentUser.role === 'employee') return;
}
const response = await api.get('/api/offices');
// Cache offices list
const response = await api.getCached('/api/offices', 60);
if (response && response.ok) {
offices = await response.json();
let filteredOffices = offices;
if (currentUser.role === 'manager') {
// Manager only sees their own office in the filter?
// Actually managers might want to filter if they (hypothetically) managed multiple,
// but currently User has 1 office.
if (currentUser.office_id) {
filteredOffices = offices.filter(o => o.id === currentUser.office_id);
} else {
@@ -254,8 +253,8 @@ async function loadClosingData() {
const promises = officeIdsToLoad.map(async (oid) => {
try {
const [weeklyRes, specificRes] = await Promise.all([
api.get(`/api/offices/${oid}/weekly-closing-days`),
api.get(`/api/offices/${oid}/closing-days`)
api.getCached(`/api/offices/${oid}/weekly-closing-days`, 60),
api.getCached(`/api/offices/${oid}/closing-days`, 60)
]);
officeClosingRules[oid] = { weekly: [], specific: [] };