diff --git a/app.json b/app.json index 65007c9..1091b42 100644 --- a/app.json +++ b/app.json @@ -25,7 +25,7 @@ "fetch" ] }, - "bundleIdentifier": "fren.onetwo.tidgi.mobile" + "bundleIdentifier": "ren.onetwo.tidgi.mobile" }, "android": { "adaptiveIcon": { diff --git a/src/services/BackgroundSyncService/index.ts b/src/services/BackgroundSyncService/index.ts index 3a3f873..508a5f3 100644 --- a/src/services/BackgroundSyncService/index.ts +++ b/src/services/BackgroundSyncService/index.ts @@ -1,6 +1,6 @@ /* eslint-disable unicorn/no-null */ /* eslint-disable @typescript-eslint/promise-function-async */ -import { asc, desc, eq, lt } from 'drizzle-orm'; +import { asc, desc, eq, gt } from 'drizzle-orm'; import * as BackgroundFetch from 'expo-background-fetch'; import * as fs from 'expo-file-system'; import * as Haptics from 'expo-haptics'; @@ -123,13 +123,8 @@ export class BackgroundSyncService { public async getChangeLogsSinceLastSync(wiki: IWikiWorkspace, lastSync: number, newerFirst?: boolean): Promise> { try { const { orm } = await sqliteServiceService.getDatabase(wiki); - const lastSyncTimestamp = new Date(lastSync).toISOString().slice(0, 19).replace('T', ' '); - - // const changeLogs = await tiddlerChangeRepo.createQueryBuilder('change') - // .where("strftime('%s', change.timestamp) > strftime('%s', :lastSyncTimestamp)", { lastSyncTimestamp }) - // .orderBy('change.timestamp', newerFirst === true ? 'DESC' : 'ASC') - // .getMany(); - const changeLogs = await orm.select().from(TiddlerChangeSQLModel).where(lt(TiddlerChangeSQLModel.timestamp, lastSyncTimestamp)).orderBy( + const lastSyncTimestamp: number = new Date(lastSync).getTime(); + const changeLogs = await orm.select().from(TiddlerChangeSQLModel).where(gt(TiddlerChangeSQLModel.timestamp, lastSyncTimestamp)).orderBy( newerFirst === true ? desc(TiddlerChangeSQLModel.timestamp) : asc(TiddlerChangeSQLModel.timestamp), ); diff --git a/src/services/SQLiteService/orm/index.ts b/src/services/SQLiteService/orm/index.ts index 1a7f662..598988a 100644 --- a/src/services/SQLiteService/orm/index.ts +++ b/src/services/SQLiteService/orm/index.ts @@ -27,5 +27,5 @@ export const TiddlerChangeSQLModel = sqliteTable('tiddlers_changes_log', { * TiddlersLogOperation */ operation: text('operation').notNull(), - timestamp: text('timestamp').notNull(), + timestamp: integer('timestamp').notNull(), }); diff --git a/src/services/SQLiteService/orm/migrations/0000_dashing_guardsmen.sql b/src/services/SQLiteService/orm/migrations/0000_grey_vengeance.sql similarity index 94% rename from src/services/SQLiteService/orm/migrations/0000_dashing_guardsmen.sql rename to src/services/SQLiteService/orm/migrations/0000_grey_vengeance.sql index 2ab0e62..91c8f5f 100644 --- a/src/services/SQLiteService/orm/migrations/0000_dashing_guardsmen.sql +++ b/src/services/SQLiteService/orm/migrations/0000_grey_vengeance.sql @@ -7,7 +7,7 @@ CREATE TABLE `tiddlers_changes_log` ( `id` integer PRIMARY KEY NOT NULL, `title` text NOT NULL, `operation` text NOT NULL, - `timestamp` text NOT NULL + `timestamp` integer NOT NULL ); --> statement-breakpoint CREATE TABLE `tiddlers` ( diff --git a/src/services/SQLiteService/orm/migrations/meta/0000_snapshot.json b/src/services/SQLiteService/orm/migrations/meta/0000_snapshot.json index 6230b18..3226a95 100644 --- a/src/services/SQLiteService/orm/migrations/meta/0000_snapshot.json +++ b/src/services/SQLiteService/orm/migrations/meta/0000_snapshot.json @@ -1,7 +1,7 @@ { "version": "5", "dialect": "sqlite", - "id": "eabb353e-c3b2-4a9c-8187-000bb5152875", + "id": "51941d56-8187-4cfe-8c99-e46c82813676", "prevId": "00000000-0000-0000-0000-000000000000", "tables": { "temp_tiddlers": { @@ -53,7 +53,7 @@ }, "timestamp": { "name": "timestamp", - "type": "text", + "type": "integer", "primaryKey": false, "notNull": true, "autoincrement": false diff --git a/src/services/SQLiteService/orm/migrations/meta/_journal.json b/src/services/SQLiteService/orm/migrations/meta/_journal.json index d939932..54f431e 100644 --- a/src/services/SQLiteService/orm/migrations/meta/_journal.json +++ b/src/services/SQLiteService/orm/migrations/meta/_journal.json @@ -5,8 +5,8 @@ { "idx": 0, "version": "5", - "when": 1705934604869, - "tag": "0000_dashing_guardsmen", + "when": 1707457512572, + "tag": "0000_grey_vengeance", "breakpoints": true } ] diff --git a/src/services/SQLiteService/orm/migrations/migrations.js b/src/services/SQLiteService/orm/migrations/migrations.js index 6d9b53a..8fa5d4a 100644 --- a/src/services/SQLiteService/orm/migrations/migrations.js +++ b/src/services/SQLiteService/orm/migrations/migrations.js @@ -1,7 +1,7 @@ // This file is required for Expo/React Native SQLite migrations - https://orm.drizzle.team/quick-sqlite/expo import journal from './meta/_journal.json'; -import m0000 from './0000_dashing_guardsmen.sql'; +import m0000 from './0000_grey_vengeance.sql'; export default { journal, diff --git a/src/services/WikiStorageService/index.ts b/src/services/WikiStorageService/index.ts index f4e1f21..fdd0c7b 100644 --- a/src/services/WikiStorageService/index.ts +++ b/src/services/WikiStorageService/index.ts @@ -112,7 +112,7 @@ export class WikiStorageService { const newOperation = { title, operation, - timestamp: new Date().toISOString(), + timestamp: Date.now(), } satisfies typeof TiddlerChangeSQLModel.$inferInsert; if (operation === TiddlersLogOperation.UPDATE) { await transaction.update(TiddlersSQLModel).set(newTiddler).where(eq(TiddlersSQLModel.title, title)); @@ -146,7 +146,7 @@ export class WikiStorageService { const newOperation = { title, operation: TiddlersLogOperation.DELETE, - timestamp: new Date().toISOString(), + timestamp: Date.now(), } satisfies typeof TiddlerChangeSQLModel.$inferInsert; await transaction.insert(TiddlerChangeSQLModel).values(newOperation); });