button zum prüfen

This commit is contained in:
2025-11-17 21:57:03 +01:00
parent cad72232d9
commit ca81121f3d
5 changed files with 87 additions and 38 deletions

View File

@@ -0,0 +1,66 @@
const { readStoreStatus, writeStoreStatus } = require('./storeStatusStore');
const storeStatusCache = new Map();
function normalizeStatusEntry(entry = {}) {
const status = Number(entry.teamSearchStatus);
const fetchedAt = Number(entry.fetchedAt) || 0;
return {
teamSearchStatus: Number.isFinite(status) ? status : null,
fetchedAt
};
}
(function bootstrapStoreStatusCache() {
try {
const cached = readStoreStatus();
Object.entries(cached || {}).forEach(([storeId, entry]) => {
if (!storeId) {
return;
}
storeStatusCache.set(String(storeId), normalizeStatusEntry(entry));
});
} catch (error) {
console.error('[STORE-STATUS] Bootstrap fehlgeschlagen:', error.message);
}
})();
function getStoreStatus(storeId) {
if (!storeId) {
return null;
}
return storeStatusCache.get(String(storeId)) || null;
}
function setStoreStatus(storeId, data = {}) {
if (!storeId) {
return null;
}
const normalized = normalizeStatusEntry(data);
storeStatusCache.set(String(storeId), normalized);
return normalized;
}
function bulkSetStoreStatus(entries = []) {
entries.forEach((entry) => {
if (!entry || !entry.storeId) {
return;
}
setStoreStatus(entry.storeId, entry);
});
}
function persistStoreStatusCache() {
const payload = {};
storeStatusCache.forEach((value, key) => {
payload[key] = value;
});
writeStoreStatus(payload);
}
module.exports = {
getStoreStatus,
setStoreStatus,
bulkSetStoreStatus,
persistStoreStatusCache
};