button zum prüfen
This commit is contained in:
40
server.js
40
server.js
@@ -13,7 +13,11 @@ const { readNotificationSettings, writeNotificationSettings } = require('./servi
|
||||
const notificationService = require('./services/notificationService');
|
||||
const { readStoreWatch, writeStoreWatch, listWatcherProfiles } = require('./services/storeWatchStore');
|
||||
const { readPreferences, writePreferences, sanitizeLocation } = require('./services/userPreferencesStore');
|
||||
const { readStoreStatus, writeStoreStatus } = require('./services/storeStatusStore');
|
||||
const {
|
||||
getStoreStatus: getCachedStoreStatusEntry,
|
||||
setStoreStatus: setCachedStoreStatusEntry,
|
||||
persistStoreStatusCache
|
||||
} = require('./services/storeStatusCache');
|
||||
|
||||
const ONE_YEAR_MS = 365 * 24 * 60 * 60 * 1000;
|
||||
const adminEmail = (process.env.ADMIN_EMAIL || '').toLowerCase();
|
||||
@@ -26,7 +30,6 @@ const cachedStoreSnapshots = new Map();
|
||||
const regionStoreCache = new Map();
|
||||
const REGION_STORE_CACHE_MS = 15 * 60 * 1000;
|
||||
const STORE_STATUS_MAX_AGE_MS = 60 * 24 * 60 * 60 * 1000;
|
||||
const storeStatusCache = new Map();
|
||||
const storeLocationIndex = new Map();
|
||||
let storeLocationIndexUpdatedAt = 0;
|
||||
const STORE_LOCATION_INDEX_TTL_MS = 12 * 60 * 60 * 1000;
|
||||
@@ -56,33 +59,6 @@ function haversineDistanceKm(lat1, lon1, lat2, lon2) {
|
||||
return R * c;
|
||||
}
|
||||
|
||||
(function bootstrapStoreStatusCache() {
|
||||
try {
|
||||
const cached = readStoreStatus();
|
||||
Object.entries(cached || {}).forEach(([storeId, entry]) => {
|
||||
if (entry && typeof entry === 'object') {
|
||||
storeStatusCache.set(String(storeId), {
|
||||
teamSearchStatus:
|
||||
entry.teamSearchStatus === null || entry.teamSearchStatus === undefined
|
||||
? null
|
||||
: Number(entry.teamSearchStatus),
|
||||
fetchedAt: Number(entry.fetchedAt) || 0
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[STORE-STATUS] Bootstrap fehlgeschlagen:', error.message);
|
||||
}
|
||||
})();
|
||||
|
||||
function persistStoreStatusCache() {
|
||||
const payload = {};
|
||||
storeStatusCache.forEach((value, key) => {
|
||||
payload[key] = value;
|
||||
});
|
||||
writeStoreStatus(payload);
|
||||
}
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: '1mb' }));
|
||||
app.use(express.static(path.join(__dirname, 'build')));
|
||||
@@ -170,7 +146,7 @@ function setCachedRegionStores(regionId, payload) {
|
||||
}
|
||||
|
||||
function getCachedStoreStatus(storeId) {
|
||||
return storeStatusCache.get(String(storeId)) || null;
|
||||
return getCachedStoreStatusEntry(storeId);
|
||||
}
|
||||
|
||||
function ingestStoreLocations(stores = []) {
|
||||
@@ -318,7 +294,7 @@ async function refreshStoreStatus(
|
||||
const changes = [];
|
||||
for (const id of storeIds) {
|
||||
const storeId = String(id);
|
||||
const entry = storeStatusCache.get(storeId);
|
||||
const entry = getCachedStoreStatus(storeId);
|
||||
const ageOk = entry && now - (entry.fetchedAt || 0) <= STORE_STATUS_MAX_AGE_MS;
|
||||
if (!force && ageOk) {
|
||||
continue;
|
||||
@@ -328,7 +304,7 @@ async function refreshStoreStatus(
|
||||
const status = Number(details?.teamSearchStatus);
|
||||
const normalized = Number.isFinite(status) ? status : null;
|
||||
const previous = entry ? entry.teamSearchStatus : null;
|
||||
storeStatusCache.set(storeId, {
|
||||
setCachedStoreStatusEntry(storeId, {
|
||||
teamSearchStatus: normalized,
|
||||
fetchedAt: now
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user