From e19ca1ec6e996966171e485786bc8fd1536625ba Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 14 Mar 2024 15:19:47 -0400 Subject: [PATCH] Use better logic for no-limit version. --- crates/db_schema/src/impls/images.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/db_schema/src/impls/images.rs b/crates/db_schema/src/impls/images.rs index cc67d9b9d..7f21592ea 100644 --- a/crates/db_schema/src/impls/images.rs +++ b/crates/db_schema/src/impls/images.rs @@ -2,7 +2,7 @@ use crate::{ newtypes::{DbUrl, LocalUserId}, schema::{local_image, remote_image}, source::images::{LocalImage, LocalImageForm, RemoteImage, RemoteImageForm}, - utils::{get_conn, limit_and_offset, limit_and_offset_unlimited, DbPool}, + utils::{get_conn, limit_and_offset, DbPool}, }; use diesel::{ dsl::exists, @@ -33,20 +33,18 @@ impl LocalImage { ignore_page_limits: bool, ) -> Result, Error> { let conn = &mut get_conn(pool).await?; - let (limit, offset) = if ignore_page_limits { - limit_and_offset_unlimited(page, limit) - } else { - limit_and_offset(page, limit)? - }; - - local_image::table + let mut query = local_image::table .filter(local_image::local_user_id.eq(user_id)) .select(local_image::all_columns) .order_by(local_image::published.desc()) - .limit(limit) - .offset(offset) - .load::(conn) - .await + .into_boxed(); + + if !ignore_page_limits { + let (limit, offset) = limit_and_offset(page, limit)?; + query = query.limit(limit).offset(offset); + } + + query.load::(conn).await } pub async fn get_all(