| 1 | use crate::db::{add_tag, create_database, remove_chunks_for_hash, remove_tag}; |
| 2 | use crate::sync; |
| 3 | |
| 4 | pub fn sync_db(tag: &sync::Tag) -> Vec<(String, String)> { |
| 5 | create_database(); |
| 6 | |
| 7 | let results = sync::sync(tag).unwrap(); |
| 8 | |
| 9 | // Send to IDE Extension to compute embeddings |
| 10 | let compute = results.0; |
| 11 | |
| 12 | // Delete chunks |
| 13 | for (_, hash) in results.1 { |
| 14 | remove_chunks_for_hash(hash); |
| 15 | } |
| 16 | |
| 17 | // Add tag from chunks |
| 18 | for (_, hash) in results.2 { |
| 19 | add_tag(hash, tag.to_string()); |
| 20 | } |
| 21 | |
| 22 | // Remove tag from chunk_rows |
| 23 | for (_, hash) in results.3 { |
| 24 | remove_tag(hash, tag.to_string()); |
| 25 | } |
| 26 | |
| 27 | return compute; |
| 28 | } |
| 29 | |
| 30 | #[cfg(test)] |
| 31 | mod tests { |
| 32 | use super::*; |
| 33 | use std::path::Path; |
| 34 | |
| 35 | #[test] |
| 36 | fn test_nothing_fails() { |
| 37 | let tag = &sync::Tag { |
| 38 | dir: Path::new("../extensions/vscode"), |
| 39 | branch: "main", |
| 40 | provider_id: "test", |
| 41 | }; |
| 42 | sync_db(tag); |
| 43 | } |
| 44 | } |