fix(database): resolve ambiguous settings query logic

- Fix PlatformServiceMixin.() ambiguous OR condition
- Use specific queries for master settings (id) vs account settings (accountDid)
- Resolve settings priority conflicts affecting server switching
- Maintain backward compatibility with existing settings structure

Testing: TypeScript compilation passes, no linting errors
Impact: Settings now load correctly without query ambiguity
This commit is contained in:
Matthew Raymer
2025-08-25 11:50:55 +00:00
parent 6aac3ca35f
commit 271a45afa3

View File

@@ -445,10 +445,22 @@ export const PlatformServiceMixin = {
fallback: Settings | null = null,
): Promise<Settings | null> {
try {
const result = await this.$dbQuery(
"SELECT * FROM settings WHERE id = ? OR accountDid = ?",
[key, key],
);
// FIXED: Use specific queries instead of ambiguous OR condition
let result;
// Check if this is a master settings key (numeric or "1")
if (key === MASTER_SETTINGS_KEY || key === "1" || !isNaN(Number(key))) {
// Master settings: query by id
result = await this.$dbQuery("SELECT * FROM settings WHERE id = ?", [
key,
]);
} else {
// Account settings: query by accountDid
result = await this.$dbQuery(
"SELECT * FROM settings WHERE accountDid = ?",
[key],
);
}
if (!result?.values?.length) {
return fallback;
@@ -763,13 +775,14 @@ export const PlatformServiceMixin = {
return defaults;
}
// **ELECTRON-SPECIFIC FIX**: Apply platform-specific API server override
// This ensures Electron always uses production endpoints regardless of cached settings
if (process.env.VITE_PLATFORM === "electron") {
// FIXED: Remove forced override - respect user preferences
// Only set default if no user preference exists
if (!settings.apiServer && process.env.VITE_PLATFORM === "electron") {
// Import constants dynamically to get platform-specific values
const { DEFAULT_ENDORSER_API_SERVER } = await import(
"../constants/app"
);
// Only set if user hasn't specified a preference
settings.apiServer = DEFAULT_ENDORSER_API_SERVER;
}
@@ -813,14 +826,17 @@ export const PlatformServiceMixin = {
defaultSettings,
);
// **ELECTRON-SPECIFIC FIX**: Force production API endpoints for Electron
// This ensures Electron doesn't use localhost development servers that might be saved in user settings
if (process.env.VITE_PLATFORM === "electron") {
// FIXED: Remove forced override - respect user preferences
// Only set default if no user preference exists
if (
!mergedSettings.apiServer &&
process.env.VITE_PLATFORM === "electron"
) {
// Import constants dynamically to get platform-specific values
const { DEFAULT_ENDORSER_API_SERVER } = await import(
"../constants/app"
);
// Only set if user hasn't specified a preference
mergedSettings.apiServer = DEFAULT_ENDORSER_API_SERVER;
}