Skip to content

Commit 6734c30

Browse files
authored
Merge pull request #4533 from tloncorp/po/electron-fix-activity-db-issue
electron: fix activity foreign key constraint issue
2 parents 71f438c + 1382e4c commit 6734c30

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

apps/tlon-desktop/electron-store-wrapper.cjs

-7
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ module.exports = {
8383
const store = await initStore();
8484
if (!store) return null;
8585
const value = store.get(key);
86-
if (key === 'encryptionKey' || key === 'encryptedAuthCookie') {
87-
console.log(
88-
`Reading ${key} from store: ${value ? 'exists' : 'missing'}`
89-
);
90-
} else {
91-
console.log(`Reading ${key} from store:`, value);
92-
}
9386
return value;
9487
} catch (error) {
9588
console.error(`Error getting ${key} from store:`, error);

apps/tlon-desktop/src/main/sqlite-service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SQLiteService {
3434
this.db.pragma('synchronous = NORMAL');
3535
this.db.pragma('temp_store = MEMORY');
3636
this.db.pragma('mmap_size = 268435456'); // 256MB mmap
37+
this.db.pragma('foreign_keys = false'); // this matches the default behavior of SQLite (foreign keys are off in both the web and mobile implementations of SQLite that we're using)
3738

3839
// Set up change notification function
3940
this.db.function('notifyChanges', (changeData: string) => {

packages/app/lib/electronDb.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class ElectronDb extends BaseDb {
9999
handleChange({
100100
table: changeData.table,
101101
operation: changeData.operation,
102-
row: JSON.parse(changeData.data || '{}'),
102+
row: changeData.data,
103103
});
104104
} catch (e) {
105105
logger.error('Failed to process change:', e);

packages/shared/src/db/changeListener.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { queryClient } from '../api';
2+
import { createDevLogger } from '../debug';
3+
4+
const logger = createDevLogger('db:changeListener', false);
25

36
let postEvents: Record<string, string[]> = {};
47

@@ -29,6 +32,7 @@ export function handleChange({
2932
* keys (`id`, `channel_id`, 'group_id`, etc.) */
3033
row?: any;
3134
}) {
35+
logger.log('handleChange, Received change', { table, operation, row });
3236
// If a post is updated, we need to refetch the post. If it's a new post, we
3337
// no-op because there's no query to invalidate.
3438
if (table === 'posts' && row && !row.parent_id && operation !== 'INSERT') {
@@ -44,6 +48,7 @@ export function handleChange({
4448
// We count updates to a post's reaction as post updates so that they trigger
4549
// channel refresh.
4650
if (table === 'post_reactions' && row) {
51+
logger.log('handleChange, Received post reaction change:', row);
4752
queryClient.refetchQueries({
4853
queryKey: ['post', row.post_id],
4954
});

0 commit comments

Comments
 (0)