From 5fd56112e5a2646d265179cbcb243a5c02694d9d Mon Sep 17 00:00:00 2001 From: augustuswm Date: Mon, 5 Feb 2024 10:00:17 -0600 Subject: [PATCH] Fix list query --- rfd-cli/src/printer/tab.rs | 7 ++++++- rfd-model/src/storage/postgres.rs | 6 ++++-- rfd-model/tests/postgres.rs | 16 +++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/rfd-cli/src/printer/tab.rs b/rfd-cli/src/printer/tab.rs index 687c6804..6dcc8854 100644 --- a/rfd-cli/src/printer/tab.rs +++ b/rfd-cli/src/printer/tab.rs @@ -652,7 +652,12 @@ impl TabDisplay for SearchResultHit { &s[..char_boundary] } - printer.print_field(tw, level, "content", &format!("{}...", get_slice_of_string(&self.content, 255))); + printer.print_field( + tw, + level, + "content", + &format!("{}...", get_slice_of_string(&self.content, 255)), + ); } } diff --git a/rfd-model/src/storage/postgres.rs b/rfd-model/src/storage/postgres.rs index 8782d647..10042be3 100644 --- a/rfd-model/src/storage/postgres.rs +++ b/rfd-model/src/storage/postgres.rs @@ -269,10 +269,12 @@ impl RfdRevisionStore for PostgresStore { query = query.filter(rfd_revision::deleted_at.is_null()); } - let results = query + let query = query .offset(pagination.offset) .limit(pagination.limit) - .order(rfd_revision::rfd_id.asc()) + .order((rfd_revision::rfd_id.asc(), rfd_revision::created_at.desc())); + + let results = query .get_results_async::(&*self.pool.get().await?) .await?; diff --git a/rfd-model/tests/postgres.rs b/rfd-model/tests/postgres.rs index 32ce2acf..f83044d9 100644 --- a/rfd-model/tests/postgres.rs +++ b/rfd-model/tests/postgres.rs @@ -15,7 +15,7 @@ use diesel_migrations::{embed_migrations, EmbeddedMigrations}; use rfd_model::{ storage::{ postgres::PostgresStore, ApiKeyFilter, ApiKeyStore, ApiUserFilter, ApiUserStore, - ListPagination, + ListPagination, RfdRevisionFilter, RfdRevisionStore, }, NewApiKey, NewApiUser, }; @@ -355,3 +355,17 @@ async fn test_api_user() { // ... #[tokio::test] async fn test_device_token() {} + +#[tokio::test] +async fn test_rfd_list() { + let db = TestDb::new("test_api_user"); + let store = PostgresStore::new(&db.url()).await.unwrap(); + + RfdRevisionStore::list_unique_rfd( + &store, + RfdRevisionFilter::default(), + &ListPagination::default(), + ) + .await + .unwrap(); +}