YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: route sync imports through WriteQueue to eliminate vision stalls
Louis Beaumont46044f23c059
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rsindex 70bb9f6e0..77198d7c7 100644--- a/crates/screenpipe-db/src/db.rs+++ b/crates/screenpipe-db/src/db.rs@@ -510,6 +510,171 @@ impl DatabaseManager {Ok(())}+ /// Insert a synced frame via the write queue. Returns the frame ID (0 if skipped due to conflict).+ pub async fn sync_insert_frame(+ &self,+ sync_id: &str,+ machine_id: &str,+ timestamp: &str,+ offset_index: i64,+ app_name: Option<&str>,+ window_name: Option<&str>,+ browser_url: Option<&str>,+ device_name: &str,+ ) -> Result<i64, sqlx::Error> {+ use crate::write_queue::{WriteOp, WriteResult};+ match self.write_queue.submit(WriteOp::SyncInsertFrame {+ sync_id: sync_id.to_string(),+ machine_id: machine_id.to_string(),+ timestamp: timestamp.to_string(),+ offset_index,+ app_name: app_name.map(|s| s.to_string()),+ window_name: window_name.map(|s| s.to_string()),+ browser_url: browser_url.map(|s| s.to_string()),+ device_name: device_name.to_string(),+ }).await? {+ WriteResult::Id(id) => Ok(id),+ _ => Ok(0),+ }+ }++ /// Insert a synced OCR record via the write queue.+ pub async fn sync_insert_ocr(+ &self,+ frame_id: i64,+ text: &str,+ focused: bool,+ app_name: &str,+ window_name: Option<&str>,+ sync_id: &str,+ ) -> Result<(), sqlx::Error> {+ use crate::write_queue::WriteOp;+ self.write_queue.submit(WriteOp::SyncInsertOcr {+ frame_id,+ text: text.to_string(),+ focused,+ app_name: app_name.to_string(),+ window_name: window_name.map(|s| s.to_string()),+ sync_id: sync_id.to_string(),+ }).await?;+ Ok(())+ }++ /// Insert a synced transcription via the write queue. Returns the audio_chunk_id.+ pub async fn sync_insert_transcription(+ &self,+ sync_id: &str,+ machine_id: &str,+ timestamp: &str,+ transcription: &str,+ device: &str,+ is_input_device: bool,+ speaker_id: Option<i64>,+ ) -> Result<i64, sqlx::Error> {+ use crate::write_queue::{WriteOp, WriteResult};+ match self.write_queue.submit(WriteOp::SyncInsertTranscription {+ sync_id: sync_id.to_string(),+ machine_id: machine_id.to_string(),+ timestamp: timestamp.to_string(),+ transcription: transcription.to_string(),+ device: device.to_string(),+ is_input_device,+ speaker_id,+ }).await? {+ WriteResult::Id(id) => Ok(id),+ _ => Ok(0),+ }+ }++ /// Insert a synced accessibility record via the write queue.+ pub async fn sync_insert_accessibility(+ &self,+ sync_id: &str,+ machine_id: &str,+ timestamp: &str,+ app_name: &str,+ window_name: &str,+ browser_url: Option<&str>,+ text_content: &str,+ ) -> Result<(), sqlx::Error> {+ use crate::write_queue::WriteOp;+ self.write_queue.submit(WriteOp::SyncInsertAccessibility {+ sync_id: sync_id.to_string(),+ machine_id: machine_id.to_string(),+ timestamp: timestamp.to_string(),+ app_name: app_name.to_string(),+ window_name: window_name.to_string(),+ browser_url: browser_url.map(|s| s.to_string()),+ text_content: text_content.to_string(),+ }).await?;+ Ok(())+ }++ /// Insert a synced UI event via the write queue.+ #[allow(clippy::too_many_arguments)]+ pub async fn sync_insert_ui_event(+ &self,+ sync_id: &str,+ machine_id: &str,+ timestamp: &str,+ event_type: &str,+ app_name: Option<&str>,+ window_title: Option<&str>,+ browser_url: Option<&str>,+ text_content: Option<&str>,+ x: Option<i32>,+ y: Option<i32>,+ key_code: Option<i32>,+ modifiers: Option<i32>,+ element_role: Option<&str>,+ element_name: Option<&str>,+ session_id: Option<&str>,+ relative_ms: Option<i32>,+ delta_x: Option<i32>,+ delta_y: Option<i32>,+ button: Option<i32>,+ click_count: Option<i32>,+ text_length: Option<i32>,+ app_pid: Option<i32>,+ element_value: Option<&str>,+ element_description: Option<&str>,+ element_automation_id: Option<&str>,+ element_bounds: Option<&str>,+ frame_id: Option<i64>,+ ) -> Result<(), sqlx::Error> {+ use crate::write_queue::WriteOp;+ self.write_queue.submit(WriteOp::SyncInsertUiEvent {+ sync_id: sync_id.to_string(),+ machine_id: machine_id.to_string(),+ timestamp: timestamp.to_string(),+ event_type: event_type.to_string(),+ app_name: app_name.map(|s| s.to_string()),+ window_title: window_title.map(|s| s.to_string()),+ browser_url: browser_url.map(|s| s.to_string()),+ text_content: text_content.map(|s| s.to_string()),+ x,+ y,+ key_code,+ modifiers,+ element_role: element_role.map(|s| s.to_string()),+ element_name: element_name.map(|s| s.to_string()),+ session_id: session_id.map(|s| s.to_string()),+ relative_ms,+ delta_x,+ delta_y,+ button,+ click_count,+ text_length,+ app_pid,+ element_value: element_value.map(|s| s.to_string()),+ element_description: element_description.map(|s| s.to_string()),+ element_automation_id: element_automation_id.map(|s| s.to_string()),+ element_bounds: element_bounds.map(|s| s.to_string()),+ frame_id,+ }).await?;+ Ok(())+ }+/// Compact snapshots via the write coalescing queue.pub async fn compact_snapshots_queued(&self, chunk_id: i64, batch: Vec<(i64, u32)>) -> Result<(), sqlx::Error> {use crate::write_queue::WriteOp;diff --git a/crates/screenpipe-db/src/write_queue.rs b/crates/screenpipe-db/src/write_queue.rsindex 46d614b60..5b5af8c68 100644--- a/crates/screenpipe-db/src/write_queue.rs+++ b/crates/screenpipe-db/src/write_queue.rs@@ -165,6 +165,76 @@ pub(crate) enum WriteOp {PipeDeleteOldExecutions {keep_per_pipe: i32,},+ /// Insert a synced frame (video_chunk + frame row) from cloud sync import.+ SyncInsertFrame {+ sync_id: String,+ machine_id: String,+ timestamp: String,+ offset_index: i64,+ app_name: Option<String>,+ window_name: Option<String>,+ browser_url: Option<String>,+ device_name: String,+ },+ /// Insert a synced OCR text row from cloud sync import.+ SyncInsertOcr {+ frame_id: i64,+ text: String,+ focused: bool,+ app_name: String,+ window_name: Option<String>,+ sync_id: String,+ },+ /// Insert a synced transcription (audio_chunk + audio_transcription) from cloud sync import.+ SyncInsertTranscription {+ sync_id: String,+ machine_id: String,+ timestamp: String,+ transcription: String,+ device: String,+ is_input_device: bool,+ speaker_id: Option<i64>,+ },+ /// Insert a synced accessibility record as a frame from cloud sync import.+ SyncInsertAccessibility {+ sync_id: String,+ machine_id: String,+ timestamp: String,+ app_name: String,+ window_name: String,+ browser_url: Option<String>,+ text_content: String,+ },+ /// Insert a synced UI event from cloud sync import.+ SyncInsertUiEvent {+ sync_id: String,+ machine_id: String,+ timestamp: String,+ event_type: String,+ app_name: Option<String>,+ window_title: Option<String>,+ browser_url: Option<String>,+ text_content: Option<String>,+ x: Option<i32>,+ y: Option<i32>,+ key_code: Option<i32>,+ modifiers: Option<i32>,+ element_role: Option<String>,+ element_name: Option<String>,+ session_id: Option<String>,+ relative_ms: Option<i32>,+ delta_x: Option<i32>,+ delta_y: Option<i32>,+ button: Option<i32>,+ click_count: Option<i32>,+ text_length: Option<i32>,+ app_pid: Option<i32>,+ element_value: Option<String>,+ element_description: Option<String>,+ element_automation_id: Option<String>,+ element_bounds: Option<String>,+ frame_id: Option<i64>,+ },/// Batch insert frames with OCR text. Replaces the direct/// `begin_immediate_with_retry` call in `insert_frames_with_ocr_batch`/// so that frame inserts go through the coalescing queue.@@ -735,6 +805,179 @@ async fn execute_single_write(Ok(WriteResult::Unit)}+ WriteOp::SyncInsertFrame {+ sync_id, machine_id, timestamp, offset_index,+ app_name, window_name, browser_url, device_name,+ } => {+ // Create a virtual video_chunk for this synced frame+ let video_chunk_id: Option<i64> = sqlx::query_scalar(+ r#"INSERT INTO video_chunks (file_path, device_name, sync_id, machine_id)+ VALUES ('cloud://' || ?1, ?2, ?1, ?3)+ ON CONFLICT DO NOTHING+ RETURNING id"#,+ )+ .bind(sync_id.as_str())+ .bind(device_name.as_str())+ .bind(machine_id.as_str())+ .fetch_optional(&mut **conn)+ .await?;++ let video_chunk_id = match video_chunk_id {+ Some(id) => id,+ None => return Ok(WriteResult::Id(0)), // conflict = already exists+ };++ let now = Utc::now().to_rfc3339();+ let frame_id = sqlx::query(+ r#"INSERT INTO frames (video_chunk_id, offset_index, timestamp, app_name, window_name, browser_url, device_name, sync_id, machine_id, synced_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)"#,+ )+ .bind(video_chunk_id)+ .bind(offset_index)+ .bind(timestamp.as_str())+ .bind(app_name.as_deref())+ .bind(window_name.as_deref())+ .bind(browser_url.as_deref())+ .bind(device_name.as_str())+ .bind(sync_id.as_str())+ .bind(machine_id.as_str())+ .bind(now.as_str())+ .execute(&mut **conn)+ .await?+ .last_insert_rowid();++ Ok(WriteResult::Id(frame_id))+ }++ WriteOp::SyncInsertOcr {+ frame_id, text, focused, app_name, window_name, sync_id,+ } => {+ let now = Utc::now().to_rfc3339();+ sqlx::query(+ r#"INSERT INTO ocr_text (frame_id, text, focused, app_name, window_name, sync_id, synced_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)"#,+ )+ .bind(frame_id)+ .bind(text.as_str())+ .bind(focused)+ .bind(app_name.as_str())+ .bind(window_name.as_deref())+ .bind(sync_id.as_str())+ .bind(now.as_str())+ .execute(&mut **conn)+ .await?;+ Ok(WriteResult::Id(*frame_id))+ }++ WriteOp::SyncInsertTranscription {+ sync_id, machine_id, timestamp, transcription, device,+ is_input_device, speaker_id,+ } => {+ let now = Utc::now().to_rfc3339();+ // Create audio chunk for synced transcription+ let audio_chunk_id: i64 = sqlx::query_scalar(+ r#"INSERT INTO audio_chunks (file_path, sync_id, machine_id)+ VALUES ('cloud://' || ?1, ?1, ?2)+ RETURNING id"#,+ )+ .bind(sync_id.as_str())+ .bind(machine_id.as_str())+ .fetch_one(&mut **conn)+ .await?;++ sqlx::query(+ r#"INSERT INTO audio_transcriptions (audio_chunk_id, offset_index, timestamp, transcription, device, is_input_device, speaker_id, sync_id, synced_at)+ VALUES (?1, 0, ?2, ?3, ?4, ?5, ?6, ?7, ?8)"#,+ )+ .bind(audio_chunk_id)+ .bind(timestamp.as_str())+ .bind(transcription.as_str())+ .bind(device.as_str())+ .bind(is_input_device)+ .bind(speaker_id)+ .bind(sync_id.as_str())+ .bind(now.as_str())+ .execute(&mut **conn)+ .await?;++ Ok(WriteResult::Id(audio_chunk_id))+ }++ WriteOp::SyncInsertAccessibility {+ sync_id, machine_id, timestamp, app_name, window_name,+ browser_url, text_content,+ } => {+ let now = Utc::now().to_rfc3339();+ let id = sqlx::query(+ r#"INSERT INTO frames (timestamp, app_name, window_name, browser_url, full_text, text_source, sync_id, machine_id, synced_at)+ VALUES (?1, ?2, ?3, ?4, ?5, 'accessibility', ?6, ?7, ?8)"#,+ )+ .bind(timestamp.as_str())+ .bind(app_name.as_str())+ .bind(window_name.as_str())+ .bind(browser_url.as_deref())+ .bind(text_content.as_str())+ .bind(sync_id.as_str())+ .bind(machine_id.as_str())+ .bind(now.as_str())+ .execute(&mut **conn)+ .await?+ .last_insert_rowid();+ Ok(WriteResult::Id(id))+ }++ WriteOp::SyncInsertUiEvent {+ sync_id, machine_id, timestamp, event_type,+ app_name, window_title, browser_url, text_content,+ x, y, key_code, modifiers, element_role, element_name,+ session_id, relative_ms, delta_x, delta_y, button, click_count,+ text_length, app_pid, element_value, element_description,+ element_automation_id, element_bounds, frame_id,+ } => {+ let now = Utc::now().to_rfc3339();+ let id = sqlx::query(+ r#"INSERT INTO ui_events (timestamp, event_type, app_name, window_title, browser_url,+ text_content, x, y, key_code, modifiers, element_role, element_name,+ session_id, relative_ms, delta_x, delta_y, button, click_count,+ text_length, app_pid, element_value, element_description,+ element_automation_id, element_bounds, frame_id,+ sync_id, machine_id, synced_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, ?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28)"#,+ )+ .bind(timestamp.as_str())+ .bind(event_type.as_str())+ .bind(app_name.as_deref())+ .bind(window_title.as_deref())+ .bind(browser_url.as_deref())+ .bind(text_content.as_deref())+ .bind(x)+ .bind(y)+ .bind(key_code)+ .bind(modifiers)+ .bind(element_role.as_deref())+ .bind(element_name.as_deref())+ .bind(session_id.as_deref())+ .bind(relative_ms)+ .bind(delta_x)+ .bind(delta_y)+ .bind(button)+ .bind(click_count)+ .bind(text_length)+ .bind(app_pid)+ .bind(element_value.as_deref())+ .bind(element_description.as_deref())+ .bind(element_automation_id.as_deref())+ .bind(element_bounds.as_deref())+ .bind(frame_id)+ .bind(sync_id.as_str())+ .bind(machine_id.as_str())+ .bind(now.as_str())+ .execute(&mut **conn)+ .await?+ .last_insert_rowid();+ Ok(WriteResult::Id(id))+ }+WriteOp::InsertFramesBatch {video_chunk_id,file_path,diff --git a/crates/screenpipe-engine/src/sync_provider.rs b/crates/screenpipe-engine/src/sync_provider.rsindex 430725bc8..fbe462f29 100644--- a/crates/screenpipe-engine/src/sync_provider.rs+++ b/crates/screenpipe-engine/src/sync_provider.rs@@ -453,8 +453,10 @@ impl ScreenpipeSyncProvider {}/// Import a sync chunk from another machine into the local database.- /// All INSERTs run inside a single transaction to avoid repeated WAL lock- /// acquisitions. Existence checks (SELECTs) use the read pool.+ /// Each record is submitted individually through the WriteQueue so that+ /// sync imports are interleaved fairly with vision/audio writes instead+ /// of holding the SQLite write lock for the entire batch.+ /// Existence checks (SELECTs) use the read pool.pub async fn import_chunk(&self, chunk: &SyncChunk) -> SyncResult<ImportResult> {let pool = &self.db.pool;let mut imported_frames = 0;@@ -479,12 +481,7 @@ impl ScreenpipeSyncProvider {});}- // Acquire a single write transaction for ALL inserts- let mut tx = self.db.begin_immediate_with_retry().await.map_err(|e| {- SyncError::Database(format!("failed to begin import transaction: {}", e))- })?;-- // Import frames+ // Import frames — each one goes through the WriteQueue individuallyfor frame in &chunk.frames {// Check if already exists (read-only, uses read pool)let exists: Option<(i64,)> = sqlx::query_as("SELECT id FROM frames WHERE sync_id = ?")@@ -498,56 +495,30 @@ impl ScreenpipeSyncProvider {continue;}- // We need a video_chunk for this frame - create a virtual one for synced data- let video_chunk_id: i64 = sqlx::query_scalar(- r#"- INSERT INTO video_chunks (file_path, device_name, sync_id, machine_id)- VALUES ('cloud://' || ?, ?, ?, ?)- ON CONFLICT DO NOTHING- RETURNING id- "#,- )- .bind(&frame.sync_id)- .bind(&frame.device_name)- .bind(&frame.sync_id)- .bind(&chunk.machine_id)- .fetch_optional(&mut **tx.conn())- .await- .map_err(|e| SyncError::Database(format!("failed to create video_chunk: {}", e)))?- .unwrap_or(0);+ let frame_id = self+ .db+ .sync_insert_frame(+ &frame.sync_id,+ &chunk.machine_id,+ &frame.timestamp,+ frame.offset_index,+ frame.app_name.as_deref(),+ frame.window_name.as_deref(),+ frame.browser_url.as_deref(),+ &frame.device_name,+ )+ .await+ .map_err(|e| SyncError::Database(format!("failed to insert frame: {}", e)))?;- if video_chunk_id == 0 {+ if frame_id == 0 {skipped += 1;continue;}- // Insert frame- sqlx::query(- r#"- INSERT INTO frames (video_chunk_id, offset_index, timestamp, app_name, window_name, browser_url, device_name, sync_id, machine_id, synced_at)- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)- "#- )- .bind(video_chunk_id)- .bind(frame.offset_index)- .bind(&frame.timestamp)- .bind(&frame.app_name)- .bind(&frame.window_name)- .bind(&frame.browser_url)- .bind(&frame.device_name)- .bind(&frame.sync_id)- .bind(&chunk.machine_id)- .bind(Utc::now().to_rfc3339())- .execute(&mut **tx.conn())- .await- .map_err(|e| SyncError::Database(format!("failed to insert frame: {}", e)))?;-imported_frames += 1;+ tokio::task::yield_now().await;}- // Yield to let other async tasks progress after frames section- tokio::task::yield_now().await;-// Build sync_id to local frame_id map (read-only, uses read pool)let frame_sync_ids: Vec<String> = chunk.frames.iter().map(|f| f.sync_id.clone()).collect();let frame_id_map: std::collections::HashMap<String, i64> = if !frame_sync_ids.is_empty() {@@ -600,32 +571,18 @@ impl ScreenpipeSyncProvider {.as_deref().or_else(|| frame_rec.and_then(|f| f.window_name.as_deref()));- sqlx::query(- r#"- INSERT INTO ocr_text (frame_id, text, focused, app_name, window_name, sync_id, synced_at)- VALUES (?, ?, ?, ?, ?, ?, ?)- "#,- )- .bind(frame_id)- .bind(&ocr.text)- .bind(ocr.focused)- .bind(app_name)- .bind(window_name)- .bind(&ocr.sync_id)- .bind(Utc::now().to_rfc3339())- .execute(&mut **tx.conn())- .await- .map_err(|e| SyncError::Database(format!("failed to insert OCR: {}", e)))?;+ self.db+ .sync_insert_ocr(frame_id, &ocr.text, ocr.focused, app_name, window_name, &ocr.sync_id)+ .await+ .map_err(|e| SyncError::Database(format!("failed to insert OCR: {}", e)))?;imported_ocr += 1;+ tokio::task::yield_now().await;} else {skipped += 1;}}- // Yield to let other async tasks progress after OCR section- tokio::task::yield_now().await;-// Import transcriptionsfor trans in &chunk.transcriptions {// Check if already exists (read-only, uses read pool)@@ -643,47 +600,23 @@ impl ScreenpipeSyncProvider {continue;}- // Create audio chunk for synced transcription- // Note: audio_chunks has no device_name column — device info is on the- // audio_transcriptions row (the `device` column) inserted below.- let audio_chunk_id: i64 = sqlx::query_scalar(- r#"- INSERT INTO audio_chunks (file_path, sync_id, machine_id)- VALUES ('cloud://' || ?, ?, ?)- RETURNING id- "#,- )- .bind(&trans.sync_id)- .bind(&trans.sync_id)- .bind(&chunk.machine_id)- .fetch_one(&mut **tx.conn())- .await- .map_err(|e| SyncError::Database(format!("failed to create audio_chunk: {}", e)))?;-- sqlx::query(- r#"- INSERT INTO audio_transcriptions (audio_chunk_id, offset_index, timestamp, transcription, device, is_input_device, speaker_id, sync_id, synced_at)- VALUES (?, 0, ?, ?, ?, ?, ?, ?, ?)- "#- )- .bind(audio_chunk_id)- .bind(&trans.timestamp)- .bind(&trans.transcription)- .bind(&trans.device)- .bind(trans.is_input_device)- .bind(trans.speaker_id)- .bind(&trans.sync_id)- .bind(Utc::now().to_rfc3339())- .execute(&mut **tx.conn())- .await- .map_err(|e| SyncError::Database(format!("failed to insert transcription: {}", e)))?;+ self.db+ .sync_insert_transcription(+ &trans.sync_id,+ &chunk.machine_id,+ &trans.timestamp,+ &trans.transcription,+ &trans.device,+ trans.is_input_device,+ trans.speaker_id,+ )+ .await+ .map_err(|e| SyncError::Database(format!("failed to insert transcription: {}", e)))?;imported_transcriptions += 1;+ tokio::task::yield_now().await;}- // Yield to let other async tasks progress after transcriptions section- tokio::task::yield_now().await;-// Import accessibility records — insert as frames with full_text// (accessibility table was dropped; text now lives in frames.full_text)let mut imported_accessibility = 0;@@ -702,32 +635,25 @@ impl ScreenpipeSyncProvider {continue;}- sqlx::query(- r#"- INSERT INTO frames (timestamp, app_name, window_name, browser_url, full_text, text_source, sync_id, machine_id, synced_at)- VALUES (?, ?, ?, ?, ?, 'accessibility', ?, ?, ?)- "#,- )- .bind(&acc.timestamp)- .bind(&acc.app_name)- .bind(&acc.window_name)- .bind(&acc.browser_url)- .bind(&acc.text_content)- .bind(&acc.sync_id)- .bind(&chunk.machine_id)- .bind(Utc::now().to_rfc3339())- .execute(&mut **tx.conn())- .await- .map_err(|e| {- SyncError::Database(format!("failed to insert accessibility as frame: {}", e))- })?;+ self.db+ .sync_insert_accessibility(+ &acc.sync_id,+ &chunk.machine_id,+ &acc.timestamp,+ &acc.app_name,+ &acc.window_name,+ acc.browser_url.as_deref(),+ &acc.text_content,+ )+ .await+ .map_err(|e| {+ SyncError::Database(format!("failed to insert accessibility as frame: {}", e))+ })?;imported_accessibility += 1;+ tokio::task::yield_now().await;}- // Yield to let other async tasks progress after accessibility section- tokio::task::yield_now().await;-// Import UI eventslet mut imported_ui_events = 0;for event in &chunk.ui_events {@@ -744,57 +670,43 @@ impl ScreenpipeSyncProvider {continue;}- sqlx::query(- r#"- INSERT INTO ui_events (timestamp, event_type, app_name, window_title, browser_url,- text_content, x, y, key_code, modifiers, element_role, element_name,- session_id, relative_ms, delta_x, delta_y, button, click_count,- text_length, app_pid, element_value, element_description,- element_automation_id, element_bounds, frame_id,- sync_id, machine_id, synced_at)- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)- "#,- )- .bind(&event.timestamp)- .bind(&event.event_type)- .bind(&event.app_name)- .bind(&event.window_title)- .bind(&event.browser_url)- .bind(&event.text_content)- .bind(event.x)- .bind(event.y)- .bind(event.key_code)- .bind(event.modifiers)- .bind(&event.element_role)- .bind(&event.element_name)- .bind(&event.session_id)- .bind(event.relative_ms)- .bind(event.delta_x)- .bind(event.delta_y)- .bind(event.button)- .bind(event.click_count)- .bind(event.text_length)- .bind(event.app_pid)- .bind(&event.element_value)- .bind(&event.element_description)- .bind(&event.element_automation_id)- .bind(&event.element_bounds)- .bind(event.frame_id)- .bind(&event.sync_id)- .bind(&chunk.machine_id)- .bind(Utc::now().to_rfc3339())- .execute(&mut **tx.conn())- .await- .map_err(|e| SyncError::Database(format!("failed to insert ui_event: {}", e)))?;+ self.db+ .sync_insert_ui_event(+ &event.sync_id,+ &chunk.machine_id,+ &event.timestamp,+ &event.event_type,+ event.app_name.as_deref(),+ event.window_title.as_deref(),+ event.browser_url.as_deref(),+ event.text_content.as_deref(),+ event.x,+ event.y,+ event.key_code,+ event.modifiers,+ event.element_role.as_deref(),+ event.element_name.as_deref(),+ event.session_id.as_deref(),+ event.relative_ms,+ event.delta_x,+ event.delta_y,+ event.button,+ event.click_count,+ event.text_length,+ event.app_pid,+ event.element_value.as_deref(),+ event.element_description.as_deref(),+ event.element_automation_id.as_deref(),+ event.element_bounds.as_deref(),+ event.frame_id,+ )+ .await+ .map_err(|e| SyncError::Database(format!("failed to insert ui_event: {}", e)))?;imported_ui_events += 1;+ tokio::task::yield_now().await;}- // Commit the single transaction for all inserts- tx.commit().await.map_err(|e| {- SyncError::Database(format!("failed to commit import transaction: {}", e))- })?;-Ok(ImportResult {imported_frames,imported_ocr,