fix: reuse cached store snapshot after logout instead of forcing refresh
This commit is contained in:
@@ -17,6 +17,7 @@ const SIXTY_DAYS_MS = 60 * 24 * 60 * 60 * 1000;
|
|||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.PORT || 3000;
|
const port = process.env.PORT || 3000;
|
||||||
const storeRefreshJobs = new Map();
|
const storeRefreshJobs = new Map();
|
||||||
|
const cachedStoreSnapshots = new Map();
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json({ limit: '1mb' }));
|
app.use(express.json({ limit: '1mb' }));
|
||||||
@@ -319,6 +320,9 @@ app.post('/api/auth/login', async (req, res) => {
|
|||||||
scheduleConfig(session.id, config, settings);
|
scheduleConfig(session.id, config, settings);
|
||||||
if (previousSession?.storesCache) {
|
if (previousSession?.storesCache) {
|
||||||
sessionStore.update(session.id, { storesCache: 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 currentSession = sessionStore.get(session.id);
|
||||||
const needsRefresh = !isStoreCacheFresh(currentSession);
|
const needsRefresh = !isStoreCacheFresh(currentSession);
|
||||||
@@ -341,6 +345,9 @@ app.post('/api/auth/login', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/auth/logout', requireAuth, (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);
|
sessionStore.delete(req.session.id);
|
||||||
credentialStore.remove(req.session.profile.id);
|
credentialStore.remove(req.session.profile.id);
|
||||||
storeRefreshJobs.delete(req.session.id);
|
storeRefreshJobs.delete(req.session.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user