From de0df4945dc061544159bda544a3a0277f16ddf9 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 4 Apr 2023 16:38:37 +1000 Subject: [PATCH] fix(nodes): fix off-by-one page count error --- invokeai/app/services/image_storage.py | 5 ++++- invokeai/app/services/sqlite.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/invokeai/app/services/image_storage.py b/invokeai/app/services/image_storage.py index 510de7c581..e9edd85d6e 100644 --- a/invokeai/app/services/image_storage.py +++ b/invokeai/app/services/image_storage.py @@ -95,7 +95,10 @@ class DiskImageStorage(ImageStorageBase): count = len(all_images) page_of_images = all_images[page * per_page : (page + 1) * per_page] - page_count = int(count / per_page) + 1 + + page_count_trunc = int(count / per_page) + page_count_mod = count % per_page + page_count = page_count_trunc if page_count_mod == 0 else page_count_trunc + 1 return PaginatedResults[ImageField]( items=page_of_images, diff --git a/invokeai/app/services/sqlite.py b/invokeai/app/services/sqlite.py index fd089014bb..9c768eb63a 100644 --- a/invokeai/app/services/sqlite.py +++ b/invokeai/app/services/sqlite.py @@ -106,10 +106,12 @@ class SqliteItemStorage(ItemStorageABC, Generic[T]): finally: self._lock.release() - pageCount = int(count / per_page) + 1 + page_count_trunc = int(count / per_page) + page_count_mod = count % per_page + page_count = page_count_trunc if page_count_mod == 0 else page_count_trunc + 1 return PaginatedResults[T]( - items=items, page=page, pages=pageCount, per_page=per_page, total=count + items=items, page=page, pages=page_count, per_page=per_page, total=count ) def search(