From 4cc895aa6421527733c2629d5e458a9c2386278b Mon Sep 17 00:00:00 2001 From: utnim2 Date: Sat, 1 Feb 2025 11:36:40 +0530 Subject: [PATCH 1/3] feat: added monitor device in vision tables and search query --- screenpipe-server/src/db.rs | 1 + screenpipe-server/src/db_types.rs | 2 ++ .../migrations/20250201060046_add_monitor_device_to_frames.sql | 3 +++ 3 files changed, 6 insertions(+) create mode 100644 screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rs index c4d2df8a2..9e2a3c6d5 100644 --- a/screenpipe-server/src/db.rs +++ b/screenpipe-server/src/db.rs @@ -746,6 +746,7 @@ impl DatabaseManager { ocr_text.app_name, ocr_text.ocr_engine, ocr_text.window_name, + video_chunks.device_name as monitor_device, GROUP_CONCAT(tags.name, ',') as tags FROM {} JOIN frames ON ocr_text.frame_id = frames.id diff --git a/screenpipe-server/src/db_types.rs b/screenpipe-server/src/db_types.rs index 8a8d066cb..7655f5fe9 100644 --- a/screenpipe-server/src/db_types.rs +++ b/screenpipe-server/src/db_types.rs @@ -36,6 +36,7 @@ pub struct OCRResultRaw { pub ocr_engine: String, pub window_name: String, pub tags: Option, + pub monitor_device: String, } #[derive(Debug, Serialize, Deserialize)] @@ -51,6 +52,7 @@ pub struct OCRResult { pub ocr_engine: String, pub window_name: String, pub tags: Vec, + pub monitor_device: String, } #[derive(Debug, Deserialize, PartialEq, Default, Clone)] diff --git a/screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql b/screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql new file mode 100644 index 000000000..bc09f27f3 --- /dev/null +++ b/screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql @@ -0,0 +1,3 @@ +-- Add migration script here +ALTER TABLE frames ADD COLUMN monitor_device TEXT NOT NULL DEFAULT ''; +CREATE INDEX idx_frames_monitor_device ON frames(monitor_device); \ No newline at end of file From f9b52d40c9f1cdc01423ca8cc36c8f5d66d54483 Mon Sep 17 00:00:00 2001 From: utnim2 Date: Sat, 1 Feb 2025 11:40:16 +0530 Subject: [PATCH 2/3] cleanup --- screenpipe-server/src/db.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rs index 9e2a3c6d5..4c042fbe8 100644 --- a/screenpipe-server/src/db.rs +++ b/screenpipe-server/src/db.rs @@ -796,6 +796,7 @@ impl DatabaseManager { app_name: raw.app_name, ocr_engine: raw.ocr_engine, window_name: raw.window_name, + monitor_device: raw.monitor_device, tags: raw .tags .map(|t| t.split(',').map(String::from).collect()) @@ -2096,6 +2097,7 @@ impl DatabaseManager { ocr_engine: raw.ocr_engine, window_name: raw.window_name, frame_name: raw.frame_name, + monitor_device: raw.monitor_device, tags: raw .tags .map(|t| t.split(',').map(String::from).collect()) From 078339ac1dced8f55230d4f04546b2645f36cc10 Mon Sep 17 00:00:00 2001 From: utnim2 Date: Sun, 2 Feb 2025 05:30:45 +0530 Subject: [PATCH 3/3] cleanup --- screenpipe-server/src/db.rs | 11 +++++++---- screenpipe-server/src/db_types.rs | 4 ++-- .../20250201060046_add_monitor_device_to_frames.sql | 3 --- .../20250201232938_add_device_name_to_chunks.sql | 3 +++ 4 files changed, 12 insertions(+), 9 deletions(-) delete mode 100644 screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql create mode 100644 screenpipe-server/src/migrations/20250201232938_add_device_name_to_chunks.sql diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rs index 4c042fbe8..1628ddf93 100644 --- a/screenpipe-server/src/db.rs +++ b/screenpipe-server/src/db.rs @@ -325,12 +325,13 @@ impl DatabaseManager { // Insert the new frame with file_path as name let id = sqlx::query( - "INSERT INTO frames (video_chunk_id, offset_index, timestamp, name) VALUES (?1, ?2, ?3, ?4)", + "INSERT INTO frames (video_chunk_id, offset_index, timestamp, name, device_name) VALUES (?1, ?2, ?3, ?4, ?5)", ) .bind(video_chunk_id) .bind(offset_index) .bind(timestamp) .bind(file_path) + .bind(device_name) .execute(&mut *tx) .await? .last_insert_rowid(); @@ -339,6 +340,8 @@ impl DatabaseManager { // Commit the transaction tx.commit().await?; + debug!("Inserted frame {} for device {}", id, device_name); + Ok(id) } @@ -746,7 +749,7 @@ impl DatabaseManager { ocr_text.app_name, ocr_text.ocr_engine, ocr_text.window_name, - video_chunks.device_name as monitor_device, + video_chunks.device_name, GROUP_CONCAT(tags.name, ',') as tags FROM {} JOIN frames ON ocr_text.frame_id = frames.id @@ -796,7 +799,7 @@ impl DatabaseManager { app_name: raw.app_name, ocr_engine: raw.ocr_engine, window_name: raw.window_name, - monitor_device: raw.monitor_device, + device_name: raw.device_name, tags: raw .tags .map(|t| t.split(',').map(String::from).collect()) @@ -2097,7 +2100,7 @@ impl DatabaseManager { ocr_engine: raw.ocr_engine, window_name: raw.window_name, frame_name: raw.frame_name, - monitor_device: raw.monitor_device, + device_name: raw.device_name, tags: raw .tags .map(|t| t.split(',').map(String::from).collect()) diff --git a/screenpipe-server/src/db_types.rs b/screenpipe-server/src/db_types.rs index 7655f5fe9..7eb38be0e 100644 --- a/screenpipe-server/src/db_types.rs +++ b/screenpipe-server/src/db_types.rs @@ -36,7 +36,7 @@ pub struct OCRResultRaw { pub ocr_engine: String, pub window_name: String, pub tags: Option, - pub monitor_device: String, + pub device_name: String, } #[derive(Debug, Serialize, Deserialize)] @@ -52,7 +52,7 @@ pub struct OCRResult { pub ocr_engine: String, pub window_name: String, pub tags: Vec, - pub monitor_device: String, + pub device_name: String, } #[derive(Debug, Deserialize, PartialEq, Default, Clone)] diff --git a/screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql b/screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql deleted file mode 100644 index bc09f27f3..000000000 --- a/screenpipe-server/src/migrations/20250201060046_add_monitor_device_to_frames.sql +++ /dev/null @@ -1,3 +0,0 @@ --- Add migration script here -ALTER TABLE frames ADD COLUMN monitor_device TEXT NOT NULL DEFAULT ''; -CREATE INDEX idx_frames_monitor_device ON frames(monitor_device); \ No newline at end of file diff --git a/screenpipe-server/src/migrations/20250201232938_add_device_name_to_chunks.sql b/screenpipe-server/src/migrations/20250201232938_add_device_name_to_chunks.sql new file mode 100644 index 000000000..444d277db --- /dev/null +++ b/screenpipe-server/src/migrations/20250201232938_add_device_name_to_chunks.sql @@ -0,0 +1,3 @@ +-- Add migration script here +ALTER TABLE frames ADD COLUMN device_name TEXT NOT NULL DEFAULT ''; +CREATE INDEX idx_frames_device_name ON frames(device_name); \ No newline at end of file