Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing latest posts #4536

Merged
merged 3 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions packages/app/lib/electronDb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { schema, setClient } from '@tloncorp/shared/db';
import { handleChange } from '@tloncorp/shared/db';
import * as kv from '@tloncorp/shared/db';
import { migrations } from '@tloncorp/shared/db/migrations';
import { drizzle } from 'drizzle-orm/sqlite-proxy';

Expand Down Expand Up @@ -128,6 +129,9 @@ export class ElectronDb extends BaseDb {
await window.sqliteBridge.purgeDb();
this.client = null;

// reset values related to tracking db sync state
await kv.headsSyncedAt.resetValue();

logger.log('Purged Electron SQLite database, reconnecting');
await this.setupDb();
}
Expand Down Expand Up @@ -170,18 +174,22 @@ export class ElectronDb extends BaseDb {
} catch (e) {
// Check if this is a "table already exists" error, which isn't fatal
if (e.message && e.message.includes('already exists')) {
logger.log('Migration contains tables that already exist, continuing', e);
logger.log(
'Migration contains tables that already exist, continuing',
e
);
return;
}
}

// For other errors, log but don't purge database
logger.error('Migration failed:', e);

// Only purge the database for critical errors that prevent app from working
if (e.message && (
e.message.includes('database is corrupted') ||
e.message.includes('database disk image is malformed')
)) {
if (
e.message &&
(e.message.includes('database is corrupted') ||
e.message.includes('database disk image is malformed'))
) {
logger.error('Database appears corrupted, purging and retrying');
await this.purgeDb();
await window.sqliteBridge.runMigrations(formattedMigrations);
Expand Down
5 changes: 5 additions & 0 deletions packages/app/lib/nativeDb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { open } from '@op-engineering/op-sqlite';
import { escapeLog } from '@tloncorp/shared';
import * as kv from '@tloncorp/shared/db';
import { schema, setClient } from '@tloncorp/shared/db';

import {
Expand Down Expand Up @@ -73,6 +74,10 @@ export class NativeDb extends BaseDb {
this.connection.delete();
this.connection = null;
this.client = null;

// reset values related to tracking db sync state
await kv.headsSyncedAt.resetValue();

logger.log('purged sqlite database, recreating');
await this.setupDb();
}
Expand Down
5 changes: 0 additions & 5 deletions packages/shared/src/db/keyValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import * as ub from '../urbit';
import { NodeBootPhase, SignupParams } from './domainTypes';
import { createStorageItem } from './storageItem';

export const activitySeenMarker = createStorageItem<number>({
key: 'activitySeenMarker',
defaultValue: 1,
});

export const pushNotificationSettings =
createStorageItem<ub.PushNotificationsSetting>({
key: 'settings:pushNotifications',
Expand Down