Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor(rust): Eliminate redundant primary keys using global uniqueness

Manav Rathi95d167878e20
diff --git a/rust/src/commands/account.rs b/rust/src/commands/account.rs
index 9514612ece..bcf8b60ff4 100644
--- a/rust/src/commands/account.rs
+++ b/rust/src/commands/account.rs
@@ -284,8 +284,10 @@ async fn add_account(
};
// Store account in database
- let account_id = storage.accounts().add(&account)?;
- storage.accounts().store_secrets(account_id, &secrets)?;
+ storage.accounts().add(&account)?;
+ storage
+ .accounts()
+ .store_secrets(account.user_id, account.app, &secrets)?;
println!("\nβœ… Account added successfully!");
println!(" Email: {email}");
@@ -344,9 +346,12 @@ async fn get_token(storage: &Storage, email: &str, app_str: &str) -> Result<()>
})?;
// Get account secrets
- let secrets = storage.accounts().get_secrets(account.id)?.ok_or_else(|| {
- crate::models::error::Error::NotFound(format!("Secrets not found for account {email}"))
- })?;
+ let secrets = storage
+ .accounts()
+ .get_secrets(account.user_id, account.app)?
+ .ok_or_else(|| {
+ crate::models::error::Error::NotFound(format!("Secrets not found for account {email}"))
+ })?;
// Token is stored as raw bytes from sealed_box_open
// The Go CLI returns it as base64 URL-encoded string WITH padding (matching TokenStr() in Go)
diff --git a/rust/src/commands/export.rs b/rust/src/commands/export.rs
index 402ffbef32..bacec5f2d9 100644
--- a/rust/src/commands/export.rs
+++ b/rust/src/commands/export.rs
@@ -75,7 +75,7 @@ async fn export_account(storage: &Storage, account: &Account) -> Result<()> {
// Get stored secrets
let secrets = storage
.accounts()
- .get_secrets(account.id)?
+ .get_secrets(account.user_id, account.app)?
.ok_or_else(|| crate::Error::NotFound("Account secrets not found".into()))?;
// Create API client with account's endpoint
diff --git a/rust/src/commands/sync.rs b/rust/src/commands/sync.rs
index 6844b5a75a..b36a37b73a 100644
--- a/rust/src/commands/sync.rs
+++ b/rust/src/commands/sync.rs
@@ -71,7 +71,7 @@ async fn sync_account(
// Get stored secrets
let secrets = storage
.accounts()
- .get_secrets(account.id)?
+ .get_secrets(account.user_id, account.app)?
.ok_or_else(|| crate::Error::NotFound("Account secrets not found".into()))?;
// Create API client with account's endpoint
@@ -157,11 +157,9 @@ async fn sync_account(
for (file, path) in download_tasks {
if path.exists() {
// File already exists, mark it as synced in database
- storage.sync().update_file_local_path(
- account.id,
- file.id,
- path.to_str().unwrap_or(""),
- )?;
+ storage
+ .sync()
+ .update_file_local_path(file.id, path.to_str().unwrap_or(""))?;
already_synced += 1;
} else {
to_download.push((file, path));
@@ -182,11 +180,9 @@ async fn sync_account(
// Update local paths in database for newly downloaded files
for (file, path) in &download_stats.successful_downloads {
- storage.sync().update_file_local_path(
- account.id,
- file.id,
- path.to_str().unwrap_or(""),
- )?;
+ storage
+ .sync()
+ .update_file_local_path(file.id, path.to_str().unwrap_or(""))?;
}
println!(
diff --git a/rust/src/storage/account.rs b/rust/src/storage/account.rs
index 71d9144daf..0f1eab7211 100644
--- a/rust/src/storage/account.rs
+++ b/rust/src/storage/account.rs
@@ -17,16 +17,16 @@ impl<'a> AccountStore<'a> {
}
/// Add a new account
- pub fn add(&self, account: &Account) -> Result<i64> {
+ pub fn add(&self, account: &Account) -> Result<()> {
let now = current_timestamp();
self.conn.execute(
- "INSERT INTO accounts (email, user_id, app, endpoint, export_dir, created_at, updated_at)
+ "INSERT INTO accounts (user_id, app, email, endpoint, export_dir, created_at, updated_at)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
params![
- account.email,
account.user_id,
format!("{:?}", account.app).to_lowercase(),
+ account.email,
account.endpoint,
account.export_dir,
now,
@@ -34,13 +34,13 @@ impl<'a> AccountStore<'a> {
],
)?;
- Ok(self.conn.last_insert_rowid())
+ Ok(())
}
/// Get an account by email and app
pub fn get(&self, email: &str, app: App) -> Result<Option<Account>> {
let mut stmt = self.conn.prepare(
- "SELECT id, email, user_id, app, endpoint, export_dir FROM accounts
+ "SELECT user_id, app, email, endpoint, export_dir FROM accounts
WHERE email = ?1 AND app = ?2",
)?;
@@ -56,7 +56,7 @@ impl<'a> AccountStore<'a> {
/// List all accounts
pub fn list(&self) -> Result<Vec<Account>> {
let mut stmt = self.conn.prepare(
- "SELECT id, email, user_id, app, endpoint, export_dir FROM accounts
+ "SELECT user_id, app, email, endpoint, export_dir FROM accounts
ORDER BY email, app",
)?;
@@ -81,22 +81,25 @@ impl<'a> AccountStore<'a> {
}
/// Delete an account
- pub fn delete(&self, account_id: i64) -> Result<()> {
- self.conn
- .execute("DELETE FROM accounts WHERE id = ?1", params![account_id])?;
+ pub fn delete(&self, user_id: i64, app: App) -> Result<()> {
+ self.conn.execute(
+ "DELETE FROM accounts WHERE user_id = ?1 AND app = ?2",
+ params![user_id, format!("{app:?}").to_lowercase()],
+ )?;
Ok(())
}
/// Store account secrets (encrypted)
- pub fn store_secrets(&self, account_id: i64, secrets: &AccountSecrets) -> Result<()> {
+ pub fn store_secrets(&self, user_id: i64, app: App, secrets: &AccountSecrets) -> Result<()> {
let now = current_timestamp();
self.conn.execute(
"INSERT OR REPLACE INTO secrets
- (account_id, token, master_key, secret_key, public_key, updated_at)
- VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
+ (user_id, app, token, master_key, secret_key, public_key, updated_at)
+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
params![
- account_id,
+ user_id,
+ format!("{app:?}").to_lowercase(),
&secrets.token,
&secrets.master_key,
&secrets.secret_key,
@@ -109,14 +112,14 @@ impl<'a> AccountStore<'a> {
}
/// Get account secrets
- pub fn get_secrets(&self, account_id: i64) -> Result<Option<AccountSecrets>> {
+ pub fn get_secrets(&self, user_id: i64, app: App) -> Result<Option<AccountSecrets>> {
let mut stmt = self.conn.prepare(
"SELECT token, master_key, secret_key, public_key FROM secrets
- WHERE account_id = ?1",
+ WHERE user_id = ?1 AND app = ?2",
)?;
let secrets = stmt
- .query_row(params![account_id], |row| {
+ .query_row(params![user_id, format!("{app:?}").to_lowercase()], |row| {
Ok(AccountSecrets {
token: row.get(0)?,
master_key: row.get(1)?,
@@ -131,7 +134,7 @@ impl<'a> AccountStore<'a> {
}
fn row_to_account(row: &Row) -> rusqlite::Result<Account> {
- let app_str: String = row.get(3)?;
+ let app_str: String = row.get(1)?;
let app = match app_str.as_str() {
"photos" => App::Photos,
"locker" => App::Locker,
@@ -140,12 +143,12 @@ fn row_to_account(row: &Row) -> rusqlite::Result<Account> {
};
Ok(Account {
- id: row.get(0)?,
- email: row.get(1)?,
- user_id: row.get(2)?,
+ id: 0, // Not used anymore, but kept for compatibility
+ user_id: row.get(0)?,
app,
- endpoint: row.get(4)?,
- export_dir: row.get(5)?,
+ email: row.get(2)?,
+ endpoint: row.get(3)?,
+ export_dir: row.get(4)?,
})
}
diff --git a/rust/src/storage/schema.rs b/rust/src/storage/schema.rs
index fd44b25249..06f16cd2de 100644
--- a/rust/src/storage/schema.rs
+++ b/rust/src/storage/schema.rs
@@ -4,16 +4,18 @@ use rusqlite::Connection;
/// Create all database tables
pub fn create_tables(conn: &Connection) -> Result<()> {
// Accounts table
+ // Note: user_id is globally unique across all users, and each user can have multiple apps
+ // So we use (user_id, app) as composite primary key
conn.execute(
"CREATE TABLE IF NOT EXISTS accounts (
- id INTEGER PRIMARY KEY,
- email TEXT NOT NULL,
user_id INTEGER NOT NULL,
app TEXT NOT NULL,
+ email TEXT NOT NULL,
endpoint TEXT NOT NULL DEFAULT 'https://api.ente.io',
export_dir TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
+ PRIMARY KEY (user_id, app),
UNIQUE(email, app, endpoint)
)",
[],
@@ -22,13 +24,15 @@ pub fn create_tables(conn: &Connection) -> Result<()> {
// Secrets table (encrypted credentials)
conn.execute(
"CREATE TABLE IF NOT EXISTS secrets (
- account_id INTEGER PRIMARY KEY,
+ user_id INTEGER NOT NULL,
+ app TEXT NOT NULL,
token BLOB NOT NULL,
master_key BLOB NOT NULL,
secret_key BLOB NOT NULL,
public_key BLOB NOT NULL,
updated_at INTEGER NOT NULL,
- FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
+ PRIMARY KEY (user_id, app),
+ FOREIGN KEY (user_id, app) REFERENCES accounts(user_id, app) ON DELETE CASCADE
)",
[],
)?;
@@ -45,27 +49,27 @@ pub fn create_tables(conn: &Connection) -> Result<()> {
// Collections/Albums table
// Note: collection_id is globally unique across all users, so we use it as the primary key
+ // owner field contains the user_id who owns this collection
conn.execute(
"CREATE TABLE IF NOT EXISTS collections (
collection_id INTEGER PRIMARY KEY,
- account_id INTEGER NOT NULL,
+ owner INTEGER NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL,
- owner INTEGER NOT NULL,
is_deleted INTEGER NOT NULL DEFAULT 0,
metadata TEXT,
- updated_at INTEGER NOT NULL,
- FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
+ updated_at INTEGER NOT NULL
)",
[],
)?;
// Files table (for caching remote file metadata)
// Note: file_id is globally unique across all users, so we use it as the primary key
+ // owner_id contains the user_id who owns this file
conn.execute(
"CREATE TABLE IF NOT EXISTS files (
file_id INTEGER PRIMARY KEY,
- account_id INTEGER NOT NULL,
+ owner_id INTEGER NOT NULL,
collection_id INTEGER NOT NULL,
encrypted_key TEXT NOT NULL,
key_decryption_nonce TEXT NOT NULL,
@@ -75,7 +79,6 @@ pub fn create_tables(conn: &Connection) -> Result<()> {
is_synced_locally INTEGER NOT NULL DEFAULT 0,
local_path TEXT,
updated_at INTEGER NOT NULL,
- FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE,
FOREIGN KEY (collection_id) REFERENCES collections(collection_id)
)",
[],
@@ -86,11 +89,9 @@ pub fn create_tables(conn: &Connection) -> Result<()> {
"CREATE TABLE IF NOT EXISTS album_files (
album_id INTEGER NOT NULL,
file_id INTEGER NOT NULL,
- account_id INTEGER NOT NULL,
synced_locally INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL,
PRIMARY KEY (album_id, file_id),
- FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE,
FOREIGN KEY (album_id) REFERENCES collections(collection_id),
FOREIGN KEY (file_id) REFERENCES files(file_id)
)",
@@ -100,12 +101,14 @@ pub fn create_tables(conn: &Connection) -> Result<()> {
// Sync state table
conn.execute(
"CREATE TABLE IF NOT EXISTS sync_state (
- account_id INTEGER PRIMARY KEY,
+ user_id INTEGER NOT NULL,
+ app TEXT NOT NULL,
last_file_sync INTEGER,
last_collection_sync INTEGER,
last_album_sync INTEGER,
sync_status TEXT,
- FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
+ PRIMARY KEY (user_id, app),
+ FOREIGN KEY (user_id, app) REFERENCES accounts(user_id, app) ON DELETE CASCADE
)",
[],
)?;
@@ -118,8 +121,8 @@ pub fn create_tables(conn: &Connection) -> Result<()> {
)?;
conn.execute(
- "CREATE INDEX IF NOT EXISTS idx_files_account
- ON files(account_id)",
+ "CREATE INDEX IF NOT EXISTS idx_files_owner
+ ON files(owner_id)",
[],
)?;
@@ -130,14 +133,14 @@ pub fn create_tables(conn: &Connection) -> Result<()> {
)?;
conn.execute(
- "CREATE INDEX IF NOT EXISTS idx_album_files_account
- ON album_files(account_id)",
+ "CREATE INDEX IF NOT EXISTS idx_collections_owner
+ ON collections(owner)",
[],
)?;
conn.execute(
- "CREATE INDEX IF NOT EXISTS idx_collections_account
- ON collections(account_id)",
+ "CREATE INDEX IF NOT EXISTS idx_accounts_email
+ ON accounts(email)",
[],
)?;
diff --git a/rust/src/storage/sync.rs b/rust/src/storage/sync.rs
index 02d45b1e25..72c6552641 100644
--- a/rust/src/storage/sync.rs
+++ b/rust/src/storage/sync.rs
@@ -17,19 +17,18 @@ impl<'a> SyncStore<'a> {
}
/// Store a collection
- pub fn upsert_collection(&self, account_id: i64, collection: &Collection) -> Result<()> {
+ pub fn upsert_collection(&self, collection: &Collection) -> Result<()> {
let metadata = serde_json::to_string(&collection)?;
self.conn.execute(
"INSERT OR REPLACE INTO collections
- (collection_id, account_id, name, type, owner, is_deleted, metadata, updated_at)
- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
+ (collection_id, owner, name, type, is_deleted, metadata, updated_at)
+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
params![
collection.id,
- account_id,
+ collection.owner,
collection.name,
format!("{:?}", collection.collection_type).to_lowercase(),
- collection.owner,
collection.is_deleted as i32,
metadata,
collection.updated_at
@@ -39,16 +38,16 @@ impl<'a> SyncStore<'a> {
Ok(())
}
- /// Get all collections for an account
- pub fn get_collections(&self, account_id: i64) -> Result<Vec<Collection>> {
+ /// Get all collections for a user
+ pub fn get_collections(&self, user_id: i64) -> Result<Vec<Collection>> {
let mut stmt = self.conn.prepare(
"SELECT metadata FROM collections
- WHERE account_id = ?1 AND is_deleted = 0
+ WHERE owner = ?1 AND is_deleted = 0
ORDER BY collection_id",
)?;
let collections = stmt
- .query_map(params![account_id], |row| {
+ .query_map(params![user_id], |row| {
let metadata: String = row.get(0)?;
Ok(serde_json::from_str::<Collection>(&metadata).unwrap())
})?
@@ -58,7 +57,7 @@ impl<'a> SyncStore<'a> {
}
/// Store a file
- pub fn upsert_file(&self, account_id: i64, file: &RemoteFile) -> Result<()> {
+ pub fn upsert_file(&self, file: &RemoteFile) -> Result<()> {
let file_info = serde_json::to_string(&file.file)?;
let metadata = serde_json::to_string(&file.metadata)?;
@@ -76,12 +75,12 @@ impl<'a> SyncStore<'a> {
self.conn.execute(
"INSERT OR REPLACE INTO files
- (file_id, account_id, collection_id, encrypted_key, key_decryption_nonce,
+ (file_id, owner_id, collection_id, encrypted_key, key_decryption_nonce,
file_info, metadata, is_deleted, is_synced_locally, updated_at)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)",
params![
file.id,
- account_id,
+ file.owner_id,
file.collection_id,
file.encrypted_key,
file.key_decryption_nonce,
@@ -99,19 +98,19 @@ impl<'a> SyncStore<'a> {
/// Get files for a collection
pub fn get_files_by_collection(
&self,
- account_id: i64,
+ user_id: i64,
collection_id: i64,
) -> Result<Vec<RemoteFile>> {
let mut stmt = self.conn.prepare(
"SELECT file_id, collection_id, encrypted_key, key_decryption_nonce,
- file_info, metadata, is_deleted, updated_at
+ file_info, metadata, is_deleted, updated_at, owner_id
FROM files
- WHERE account_id = ?1 AND collection_id = ?2 AND is_deleted = 0
+ WHERE owner_id = ?1 AND collection_id = ?2 AND is_deleted = 0
ORDER BY file_id",
)?;
let files = stmt
- .query_map(params![account_id, collection_id], |row| {
+ .query_map(params![user_id, collection_id], |row| {
let file_info: String = row.get(4)?;
let metadata: String = row.get(5)?;
@@ -134,7 +133,7 @@ impl<'a> SyncStore<'a> {
Ok(RemoteFile {
id: row.get(0)?,
collection_id: row.get(1)?,
- owner_id: 0, // Will need to fetch from account
+ owner_id: row.get(8)?,
encrypted_key: row.get(2)?,
key_decryption_nonce: row.get(3)?,
file: file_obj,
@@ -150,19 +149,15 @@ impl<'a> SyncStore<'a> {
}
/// Update sync state
- pub fn update_sync_state(
- &self,
- account_id: i64,
- sync_type: &str,
- timestamp: i64,
- ) -> Result<()> {
+ pub fn update_sync_state(&self, user_id: i64, sync_type: &str, timestamp: i64) -> Result<()> {
// For per-collection sync, store as generic key-value
if sync_type.starts_with("collection_") {
// Use a more generic approach for per-collection sync
+ // Note: We're assuming photos app for now - might need app parameter in future
self.conn.execute(
- "INSERT OR REPLACE INTO sync_state (account_id, last_file_sync) VALUES (?1, ?2)
- ON CONFLICT(account_id) DO UPDATE SET last_file_sync = MAX(last_file_sync, ?2)",
- params![account_id, timestamp],
+ "INSERT OR REPLACE INTO sync_state (user_id, app, last_file_sync) VALUES (?1, 'photos', ?2)
+ ON CONFLICT(user_id, app) DO UPDATE SET last_file_sync = MAX(last_file_sync, ?2)",
+ params![user_id, timestamp],
)?;
return Ok(());
}
@@ -175,17 +170,17 @@ impl<'a> SyncStore<'a> {
};
let query = format!(
- "INSERT OR REPLACE INTO sync_state (account_id, {column}) VALUES (?1, ?2)
- ON CONFLICT(account_id) DO UPDATE SET {column} = ?2"
+ "INSERT OR REPLACE INTO sync_state (user_id, app, {column}) VALUES (?1, 'photos', ?2)
+ ON CONFLICT(user_id, app) DO UPDATE SET {column} = ?2"
);
- self.conn.execute(&query, params![account_id, timestamp])?;
+ self.conn.execute(&query, params![user_id, timestamp])?;
Ok(())
}
/// Get last sync timestamp
- pub fn get_last_sync(&self, account_id: i64, sync_type: &str) -> Result<Option<i64>> {
+ pub fn get_last_sync(&self, user_id: i64, sync_type: &str) -> Result<Option<i64>> {
// For per-collection sync, just return 0 for now
if sync_type.starts_with("collection_") {
return Ok(Some(0));
@@ -198,11 +193,12 @@ impl<'a> SyncStore<'a> {
_ => return Err(crate::Error::InvalidInput("Invalid sync type".into())),
};
- let query = format!("SELECT {column} FROM sync_state WHERE account_id = ?1");
+ let query =
+ format!("SELECT {column} FROM sync_state WHERE user_id = ?1 AND app = 'photos'");
let mut stmt = self.conn.prepare(&query)?;
let timestamp = stmt
- .query_row(params![account_id], |row| row.get::<_, Option<i64>>(0))
+ .query_row(params![user_id], |row| row.get::<_, Option<i64>>(0))
.optional()?
.flatten();
@@ -210,50 +206,45 @@ impl<'a> SyncStore<'a> {
}
/// Mark album file as synced
- pub fn mark_album_file_synced(
- &self,
- account_id: i64,
- album_id: i64,
- file_id: i64,
- ) -> Result<()> {
+ pub fn mark_album_file_synced(&self, album_id: i64, file_id: i64) -> Result<()> {
self.conn.execute(
"UPDATE album_files SET synced_locally = 1
- WHERE account_id = ?1 AND album_id = ?2 AND file_id = ?3",
- params![account_id, album_id, file_id],
+ WHERE album_id = ?1 AND file_id = ?2",
+ params![album_id, file_id],
)?;
Ok(())
}
/// Clear sync state for an account (for full sync)
- pub fn clear_sync_state(&self, account_id: i64) -> Result<()> {
+ pub fn clear_sync_state(&self, user_id: i64) -> Result<()> {
self.conn.execute(
- "DELETE FROM sync_state WHERE account_id = ?1",
- params![account_id],
+ "DELETE FROM sync_state WHERE user_id = ?1 AND app = 'photos'",
+ params![user_id],
)?;
Ok(())
}
/// Get files that need downloading (not synced locally)
- pub fn get_pending_downloads(&self, account_id: i64) -> Result<Vec<RemoteFile>> {
+ pub fn get_pending_downloads(&self, user_id: i64) -> Result<Vec<RemoteFile>> {
// First check how many files are already synced
let synced_count: i64 = self.conn.query_row(
- "SELECT COUNT(*) FROM files WHERE account_id = ?1 AND is_synced_locally = 1",
- params![account_id],
+ "SELECT COUNT(*) FROM files WHERE owner_id = ?1 AND is_synced_locally = 1",
+ params![user_id],
|row| row.get(0),
)?;
log::debug!("Files already synced locally: {synced_count}");
let mut stmt = self.conn.prepare(
"SELECT file_id, collection_id, encrypted_key, key_decryption_nonce,
- file_info, metadata, is_deleted, updated_at
+ file_info, metadata, is_deleted, updated_at, owner_id
FROM files
- WHERE account_id = ?1 AND is_deleted = 0 AND is_synced_locally = 0
+ WHERE owner_id = ?1 AND is_deleted = 0 AND is_synced_locally = 0
ORDER BY file_id",
)?;
let files = stmt
- .query_map(params![account_id], |row| {
+ .query_map(params![user_id], |row| {
let file_info: String = row.get(4)?;
let metadata: String = row.get(5)?;
@@ -276,7 +267,7 @@ impl<'a> SyncStore<'a> {
Ok(RemoteFile {
id: row.get(0)?,
collection_id: row.get(1)?,
- owner_id: 0, // Will need to fetch from account
+ owner_id: row.get(8)?,
encrypted_key: row.get(2)?,
key_decryption_nonce: row.get(3)?,
file: file_obj,
@@ -292,12 +283,7 @@ impl<'a> SyncStore<'a> {
}
/// Mark file as synced locally after successful download
- pub fn mark_file_synced(
- &self,
- account_id: i64,
- file_id: i64,
- local_path: Option<&str>,
- ) -> Result<()> {
+ pub fn mark_file_synced(&self, file_id: i64, local_path: Option<&str>) -> Result<()> {
let rows_updated = if let Some(path) = local_path {
self.conn.execute(
"UPDATE files SET is_synced_locally = 1, local_path = ?2
@@ -312,20 +298,13 @@ impl<'a> SyncStore<'a> {
)?
};
- log::debug!(
- "Marked file {file_id} (account {account_id}) as synced locally, rows affected: {rows_updated}"
- );
+ log::debug!("Marked file {file_id} as synced locally, rows affected: {rows_updated}");
Ok(())
}
/// Update file local path (legacy method - consider using mark_file_synced instead)
- pub fn update_file_local_path(
- &self,
- account_id: i64,
- file_id: i64,
- local_path: &str,
- ) -> Result<()> {
- self.mark_file_synced(account_id, file_id, Some(local_path))
+ pub fn update_file_local_path(&self, file_id: i64, local_path: &str) -> Result<()> {
+ self.mark_file_synced(file_id, Some(local_path))
}
}
diff --git a/rust/src/sync/engine.rs b/rust/src/sync/engine.rs
index 5c3f362df9..278aac568f 100644
--- a/rust/src/sync/engine.rs
+++ b/rust/src/sync/engine.rs
@@ -88,7 +88,7 @@ impl SyncEngine {
};
// Upsert collection (insert or update)
- sync_store.upsert_collection(self.account.id, &storage_collection)?;
+ sync_store.upsert_collection(&storage_collection)?;
// Count as new or updated based on updation time
if collection.updation_time > last_sync {
@@ -103,7 +103,7 @@ impl SyncEngine {
// Update sync timestamp
let now = chrono::Utc::now().timestamp_micros();
- sync_store.update_sync_state(self.account.id, "collections", now)?;
+ sync_store.update_sync_state(self.account.user_id, "collections", now)?;
log::info!(
"Collections synced: {} new, {} updated",
@@ -199,7 +199,7 @@ impl SyncEngine {
};
// Upsert file (insert or update)
- sync_store.upsert_file(self.account.id, &remote_file)?;
+ sync_store.upsert_file(&remote_file)?;
// Count as new or updated
if file.updation_time > last_sync {