mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
@@ -141,6 +141,18 @@ export class SQLiteAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkpoint() {
|
||||||
|
try {
|
||||||
|
if (!this.db) {
|
||||||
|
logger.warn(`${this.path} is not connected`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.db.checkpoint();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('checkpoint', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getUpdatesCount(docId?: string) {
|
async getUpdatesCount(docId?: string) {
|
||||||
try {
|
try {
|
||||||
if (!this.db) {
|
if (!this.db) {
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ export class WorkspaceSQLiteDB {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async checkpoint() {
|
||||||
|
await this.adapter.checkpoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function openWorkspaceDatabase(
|
export async function openWorkspaceDatabase(
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ export async function saveDBFileAs(
|
|||||||
): Promise<SaveDBFileResult> {
|
): Promise<SaveDBFileResult> {
|
||||||
try {
|
try {
|
||||||
const db = await ensureSQLiteDB('workspace', workspaceId);
|
const db = await ensureSQLiteDB('workspace', workspaceId);
|
||||||
|
await db.checkpoint(); // make sure all changes (WAL) are written to db
|
||||||
const fakedResult = getFakedResult();
|
const fakedResult = getFakedResult();
|
||||||
|
|
||||||
const ret =
|
const ret =
|
||||||
|
|||||||
@@ -98,8 +98,6 @@ export const registerUpdater = async () => {
|
|||||||
channel: buildType,
|
channel: buildType,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug('auto-updater feed config', feedUrl);
|
|
||||||
|
|
||||||
autoUpdater.setFeedURL(feedUrl);
|
autoUpdater.setFeedURL(feedUrl);
|
||||||
|
|
||||||
// register events for checkForUpdates
|
// register events for checkForUpdates
|
||||||
|
|||||||
5
packages/frontend/native/index.d.ts
vendored
5
packages/frontend/native/index.d.ts
vendored
@@ -30,6 +30,11 @@ export declare class SqliteConnection {
|
|||||||
get isClose(): boolean
|
get isClose(): boolean
|
||||||
static validate(path: string): Promise<ValidationResult>
|
static validate(path: string): Promise<ValidationResult>
|
||||||
migrateAddDocId(): Promise<void>
|
migrateAddDocId(): Promise<void>
|
||||||
|
/**
|
||||||
|
* Flush the WAL file to the database file.
|
||||||
|
* See https://www.sqlite.org/pragma.html#pragma_wal_checkpoint:~:text=PRAGMA%20schema.wal_checkpoint%3B
|
||||||
|
*/
|
||||||
|
checkpoint(): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BlobRow {
|
export interface BlobRow {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ impl SqliteConnection {
|
|||||||
let sqlite_options = SqliteConnectOptions::new()
|
let sqlite_options = SqliteConnectOptions::new()
|
||||||
.filename(&path)
|
.filename(&path)
|
||||||
.foreign_keys(false)
|
.foreign_keys(false)
|
||||||
.journal_mode(sqlx::sqlite::SqliteJournalMode::Off);
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal);
|
||||||
let pool = SqlitePoolOptions::new()
|
let pool = SqlitePoolOptions::new()
|
||||||
.max_connections(4)
|
.max_connections(4)
|
||||||
.connect_lazy_with(sqlite_options);
|
.connect_lazy_with(sqlite_options);
|
||||||
@@ -490,6 +490,19 @@ impl SqliteConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush the WAL file to the database file.
|
||||||
|
* See https://www.sqlite.org/pragma.html#pragma_wal_checkpoint:~:text=PRAGMA%20schema.wal_checkpoint%3B
|
||||||
|
*/
|
||||||
|
#[napi]
|
||||||
|
pub async fn checkpoint(&self) -> napi::Result<()> {
|
||||||
|
sqlx::query("PRAGMA wal_checkpoint(FULL);")
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(anyhow::Error::from)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn migrate_add_doc_id_index(&self) -> napi::Result<()> {
|
pub async fn migrate_add_doc_id_index(&self) -> napi::Result<()> {
|
||||||
// ignore errors
|
// ignore errors
|
||||||
match sqlx::query("CREATE INDEX IF NOT EXISTS idx_doc_id ON updates(doc_id);")
|
match sqlx::query("CREATE INDEX IF NOT EXISTS idx_doc_id ON updates(doc_id);")
|
||||||
|
|||||||
Reference in New Issue
Block a user