diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index cc838cf..c813b94 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -191,7 +191,12 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { async fn forge_type_exists(&self, forge_type: &ForgeImplementation) -> DBResult; /// Get all forges - async fn get_all_forges(&self, offset: u32, limit: u32) -> DBResult>; + async fn get_all_forges( + &self, + with_imports: bool, + offset: u32, + limit: u32, + ) -> DBResult>; /// add new user to database async fn add_user(&self, u: &AddUser) -> DBResult<()>; diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index bfb64d5..039f189 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -35,7 +35,7 @@ pub async fn adding_forge_works<'a, T: SCDatabase>( { let forge = db.get_forge(&create_forge_msg.url).await.unwrap(); - let forges = db.get_all_forges(0, 10).await.unwrap(); + let forges = db.get_all_forges(true, 0, 10).await.unwrap(); assert_eq!(forges.len(), 1); assert_eq!( diff --git a/db/db-sqlx-sqlite/src/lib.rs b/db/db-sqlx-sqlite/src/lib.rs index 72fe0c6..64d0e76 100644 --- a/db/db-sqlx-sqlite/src/lib.rs +++ b/db/db-sqlx-sqlite/src/lib.rs @@ -307,10 +307,16 @@ impl SCDatabase for Database { } /// Get all forges - async fn get_all_forges(&self, offset: u32, limit: u32) -> DBResult> { - let mut inter_forges = sqlx::query_as!( - InnerForge, - "SELECT + async fn get_all_forges( + &self, + with_imports: bool, + offset: u32, + limit: u32, + ) -> DBResult> { + let mut inter_forges = if with_imports { + sqlx::query_as!( + InnerForge, + "SELECT hostname, last_crawl_on, starchart_forge_type.name, @@ -325,12 +331,39 @@ impl SCDatabase for Database { starchart_forges.ID LIMIT $1 OFFSET $2; ", - limit, - offset - ) - .fetch_all(&self.pool) - .await - .map_err(|e| DBError::DBError(Box::new(e)))?; + limit, + offset + ) + .fetch_all(&self.pool) + .await + .map_err(|e| DBError::DBError(Box::new(e)))? + } else { + sqlx::query_as!( + InnerForge, + "SELECT + hostname, + last_crawl_on, + starchart_forge_type.name, + imported + FROM + starchart_forges + INNER JOIN + starchart_forge_type + ON + starchart_forges.forge_type = starchart_forge_type.id + WHERE + starchart_forges.imported = false + ORDER BY + starchart_forges.ID + LIMIT $1 OFFSET $2; + ", + limit, + offset + ) + .fetch_all(&self.pool) + .await + .map_err(|e| DBError::DBError(Box::new(e)))? + }; let mut forges: Vec = Vec::with_capacity(inter_forges.len()); inter_forges.drain(0..).for_each(|f| forges.push(f.into())); diff --git a/src/api.rs b/src/api.rs index dae5dfe..f94c5f7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -33,7 +33,7 @@ pub async fn forges(db: WebDB, q: web::Query) -> ServiceResult