From 1f629cc02d6e2e39d45429d0330bd7c5465f1b25 Mon Sep 17 00:00:00 2001 From: Freek van Zee Date: Sun, 14 Apr 2024 12:44:46 +0200 Subject: [PATCH] Add ignore_page_limits for custom emojis EmojiPicker needs to be able to retrieve all emojis in 1 call --- crates/api_common/src/custom_emoji.rs | 1 + crates/api_crud/src/custom_emoji/list.rs | 10 ++++++++-- crates/db_views/src/custom_emoji_view.rs | 10 +++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/api_common/src/custom_emoji.rs b/crates/api_common/src/custom_emoji.rs index 7a846eae2..3804b71af 100644 --- a/crates/api_common/src/custom_emoji.rs +++ b/crates/api_common/src/custom_emoji.rs @@ -65,4 +65,5 @@ pub struct ListCustomEmojis { pub page: Option, pub limit: Option, pub category: Option, + pub ignore_page_limits: Option, } diff --git a/crates/api_crud/src/custom_emoji/list.rs b/crates/api_crud/src/custom_emoji/list.rs index c60a03ed4..6ee5a44b0 100644 --- a/crates/api_crud/src/custom_emoji/list.rs +++ b/crates/api_crud/src/custom_emoji/list.rs @@ -12,8 +12,14 @@ pub async fn list_custom_emojis( local_user_view: Option, context: Data, ) -> Result, LemmyError> { - let custom_emojis = - CustomEmojiView::list(&mut context.pool(), &data.category, data.page, data.limit).await?; + let custom_emojis = CustomEmojiView::list( + &mut context.pool(), + &data.category, + data.page, + data.limit, + data.ignore_page_limits.unwrap_or(false), + ) + .await?; Ok(Json(ListCustomEmojisResponse { custom_emojis })) } diff --git a/crates/db_views/src/custom_emoji_view.rs b/crates/db_views/src/custom_emoji_view.rs index 8c17190a2..1ee40fac3 100644 --- a/crates/db_views/src/custom_emoji_view.rs +++ b/crates/db_views/src/custom_emoji_view.rs @@ -58,15 +58,21 @@ impl CustomEmojiView { category: &Option, page: Option, limit: Option, + ignore_page_limits: bool, ) -> Result, Error> { let conn = &mut get_conn(pool).await?; - let (limit, offset) = limit_and_offset(page, limit)?; + let mut query = custom_emoji::table .left_join( custom_emoji_keyword::table.on(custom_emoji_keyword::custom_emoji_id.eq(custom_emoji::id)), ) .into_boxed(); + if !ignore_page_limits { + let (limit, offset) = limit_and_offset(page, limit)?; + query = query.limit(limit).offset(offset); + } + if let Some(category) = category { query = query.filter(custom_emoji::category.eq(category)) } @@ -78,8 +84,6 @@ impl CustomEmojiView { custom_emoji::all_columns, custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want) )) - .limit(limit) - .offset(offset) .load::(conn) .await?;