fix: reuse cached store snapshot after logout instead of forcing refresh

This commit is contained in:
root
2025-11-09 16:51:01 +01:00
parent 0d09fdbcdc
commit 63e547a4c1

View File

@@ -17,6 +17,7 @@ const SIXTY_DAYS_MS = 60 * 24 * 60 * 60 * 1000;
const app = express();
const port = process.env.PORT || 3000;
const storeRefreshJobs = new Map();
const cachedStoreSnapshots = new Map();
app.use(cors());
app.use(express.json({ limit: '1mb' }));
@@ -302,7 +303,7 @@ app.post('/api/auth/login', async (req, res) => {
const existingCredentials = credentialStore.get(profile.id);
const existingToken = existingCredentials?.token;
const previousSession = existingToken ? sessionStore.get(existingToken) : null;
const previousSession = existingToken ? sessionStore.get(existingToken) : null;
if (existingToken) {
sessionStore.delete(existingToken);
}
@@ -319,6 +320,9 @@ app.post('/api/auth/login', async (req, res) => {
scheduleConfig(session.id, config, settings);
if (previousSession?.storesCache) {
sessionStore.update(session.id, { storesCache: previousSession.storesCache });
} else if (cachedStoreSnapshots.has(profile.id)) {
sessionStore.update(session.id, { storesCache: cachedStoreSnapshots.get(profile.id) });
cachedStoreSnapshots.delete(profile.id);
}
const currentSession = sessionStore.get(session.id);
const needsRefresh = !isStoreCacheFresh(currentSession);
@@ -341,6 +345,9 @@ app.post('/api/auth/login', async (req, res) => {
});
app.post('/api/auth/logout', requireAuth, (req, res) => {
if (req.session?.profile?.id && req.session?.storesCache) {
cachedStoreSnapshots.set(req.session.profile.id, req.session.storesCache);
}
sessionStore.delete(req.session.id);
credentialStore.remove(req.session.profile.id);
storeRefreshJobs.delete(req.session.id);