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