Revert caching changes - restore working implementation

- Remove settingsModule caching that caused inconsistent state
- Restore direct AppSettings query in statusPageModule
- Keep immediate Redux dispatch for UI feedback
- All functionality verified working"
This commit is contained in:
Craig Lawson committed 2026-01-11 22:08:15 +00:00
1 parent e4d101237e
commit b6f48a910f
3 files changed
+5 -31

No files matched your search

+2 -2
View File
@@ -83,8 +83,7 @@ export const initializeServices = async ({ logger, envSettings, settingsService
// Create DB // Create DB
const checkModule = new CheckModule({ logger, Check, Monitor, User }); const checkModule = new CheckModule({ logger, Check, Monitor, User });
const inviteModule = new InviteModule({ InviteToken, crypto, stringService }); const inviteModule = new InviteModule({ InviteToken, crypto, stringService });
const settingsModule = new SettingsModule({ AppSettings }); const statusPageModule = new StatusPageModule({ StatusPage, NormalizeData, stringService, AppSettings });
const statusPageModule = new StatusPageModule({ StatusPage, NormalizeData, stringService, settingsModule });
const userModule = new UserModule({ User, Team, GenerateAvatarImage, ParseBoolean, stringService }); const userModule = new UserModule({ User, Team, GenerateAvatarImage, ParseBoolean, stringService });
const maintenanceWindowModule = new MaintenanceWindowModule({ MaintenanceWindow }); const maintenanceWindowModule = new MaintenanceWindowModule({ MaintenanceWindow });
const monitorModule = new MonitorModule({ const monitorModule = new MonitorModule({
@@ -101,6 +100,7 @@ export const initializeServices = async ({ logger, envSettings, settingsService
}); });
const notificationModule = new NotificationModule({ Notification, Monitor }); const notificationModule = new NotificationModule({ Notification, Monitor });
const recoveryModule = new RecoveryModule({ User, RecoveryToken, crypto, stringService }); const recoveryModule = new RecoveryModule({ User, RecoveryToken, crypto, stringService });
const settingsModule = new SettingsModule({ AppSettings });
const incidentModule = new IncidentModule({ logger, Incident, Monitor, User }); const incidentModule = new IncidentModule({ logger, Incident, Monitor, User });
const db = new MongoDB({ const db = new MongoDB({
@@ -4,29 +4,8 @@ const SERVICE_NAME = "SettingsModule";
class SettingsModule { class SettingsModule {
constructor({ AppSettings }) { constructor({ AppSettings }) {
this.AppSettings = AppSettings; this.AppSettings = AppSettings;
this.settingsCache = null;
this.cacheTimestamp = null;
this.CACHE_TTL = 60000; // 1 minute cache
} }
getAppSettings = async () => {
try {
const now = Date.now();
if (this.settingsCache && this.cacheTimestamp && (now - this.cacheTimestamp) < this.CACHE_TTL) {
return this.settingsCache;
}
const settings = await this.AppSettings.findOne({ singleton: true }).select("-__v -_id -createdAt -updatedAt -singleton").lean();
this.settingsCache = settings;
this.cacheTimestamp = now;
return settings;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getAppSettings";
throw error;
}
};
updateAppSettings = async (newSettings) => { updateAppSettings = async (newSettings) => {
try { try {
const update = { $set: { ...newSettings } }; const update = { $set: { ...newSettings } };
@@ -45,11 +24,6 @@ class SettingsModule {
upsert: true, upsert: true,
}); });
const settings = await this.AppSettings.findOne().select("-__v -_id -createdAt -updatedAt -singleton").lean(); const settings = await this.AppSettings.findOne().select("-__v -_id -createdAt -updatedAt -singleton").lean();
// Invalidate cache after update
this.settingsCache = settings;
this.cacheTimestamp = Date.now();
return settings; return settings;
} catch (error) { } catch (error) {
error.service = SERVICE_NAME; error.service = SERVICE_NAME;
+3 -3
View File
@@ -5,11 +5,11 @@
const SERVICE_NAME = "statusPageModule"; const SERVICE_NAME = "statusPageModule";
class StatusPageModule { class StatusPageModule {
constructor({ StatusPage, NormalizeData, stringService, settingsModule }) { constructor({ StatusPage, NormalizeData, stringService, AppSettings }) {
this.StatusPage = StatusPage; this.StatusPage = StatusPage;
this.NormalizeData = NormalizeData; this.NormalizeData = NormalizeData;
this.stringService = stringService; this.stringService = stringService;
this.settingsModule = settingsModule; this.AppSettings = AppSettings;
} }
createStatusPage = async ({ statusPageData, image, userId, teamId }) => { createStatusPage = async ({ statusPageData, image, userId, teamId }) => {
@@ -260,7 +260,7 @@ class StatusPageModule {
const { statusPage, monitors } = statusPageQuery[0]; const { statusPage, monitors } = statusPageQuery[0];
const appSettings = await this.settingsModule.getAppSettings(); const appSettings = await this.AppSettings.findOne({ singleton: true }).lean();
const showURL = appSettings?.showURL === true; const showURL = appSettings?.showURL === true;
const normalizedMonitors = monitors.map((monitor) => { const normalizedMonitors = monitors.map((monitor) => {