Skip to content

Commit 1f10cd3

Browse files
committed
fix: stop pagination after short catalog pages
1 parent 9f5a210 commit 1f10cd3

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/models/catalog_with_filters.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::constants::{SKIP_EXTRA_PROP, TYPE_PRIORITIES};
1+
use crate::constants::{CATALOG_PAGE_SIZE, SKIP_EXTRA_PROP, TYPE_PRIORITIES};
22
use crate::models::common::{
33
compare_with_priorities, eq_update, resource_update_with_vector_content, ResourceAction,
44
ResourceLoadable,
@@ -28,6 +28,9 @@ pub trait CatalogResourceAdapter {
2828
fn resource() -> &'static str;
2929
fn catalogs(manifest: &Manifest) -> &[ManifestCatalog];
3030
fn selectable_priority() -> SelectablePriority;
31+
fn page_size() -> Option<usize> {
32+
None
33+
}
3134
}
3235

3336
impl CatalogResourceAdapter for MetaItemPreview {
@@ -40,6 +43,9 @@ impl CatalogResourceAdapter for MetaItemPreview {
4043
fn selectable_priority() -> SelectablePriority {
4144
SelectablePriority::Type
4245
}
46+
fn page_size() -> Option<usize> {
47+
Some(CATALOG_PAGE_SIZE)
48+
}
4349
}
4450

4551
impl CatalogResourceAdapter for DescriptorPreview {
@@ -485,7 +491,11 @@ fn selectable_update<T: CatalogResourceAdapter>(
485491
page.content
486492
.as_ref()
487493
.and_then(|content| content.ready())
488-
.filter(|content| !content.is_empty())
494+
.filter(|content| {
495+
T::page_size()
496+
.map(|page_size| content.len() == page_size)
497+
.unwrap_or_else(|| !content.is_empty())
498+
})
489499
.map(|content| content.len())
490500
})
491501
.collect::<Option<Vec<_>>>()

src/unit_tests/catalog_with_filters/load_action.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::constants::CATALOG_PAGE_SIZE;
12
use crate::models::catalog_with_filters::{CatalogWithFilters, Selected};
23
use crate::models::common::{Loadable, ResourceLoadable};
34
use crate::models::ctx::Ctx;
@@ -38,7 +39,7 @@ fn default_catalog() {
3839
&& method == "GET" =>
3940
{
4041
future::ok(Box::new(ResourceResponse::Metas {
41-
metas: vec![MetaItemPreview::default()],
42+
metas: vec![MetaItemPreview::default(); CATALOG_PAGE_SIZE],
4243
}) as Box<dyn Any + Send>)
4344
.boxed_env()
4445
}
@@ -219,7 +220,7 @@ fn search_catalog() {
219220
..
220221
})
221222
);
222-
assert!(states[2].discover.selectable.next_page.is_some());
223+
assert!(states[2].discover.selectable.next_page.is_none());
223224
assert_matches!(
224225
states[2].discover.catalog.first(),
225226
Some(ResourceLoadable {

0 commit comments

Comments
 (0)