Skip to content

Commit b0db123

Browse files
authored
Fix: Adjust pagination metadata when fetching projects with an assignee filter (#18)
### Description This PR fixes a pagination bug in the `projects list` command. Previously, when using filters that required fetching all pages and processing them locally (e.g., filtering by `assignee`), the command still parsed the raw API metadata for `totalPages` and `totalCount`. This led to a misleading summary indicating many pages (like "Page 1/36") even when the local filtering only returned a handful of results that fit completely on a single page. The output logic has been updated so that when `fetch_all` is triggered, the displayed "total pages" and "total items" are correctly calculated from the localized result set. ### How to Test 1. Run `python -m conviso.app projects list --company-id <ID> --filter assignee=<EMAIL>`. 2. Observe the output summary in the footer and title. 3. **Expected behavior:** The pagination metrics should represent the exact number of matching projects found and should display as `page 1/1` rather than retaining the unfiltered total counts from the initial API metadata. 4. Run without the assignee filter and verify that normal pagination limits remain standard and unbroken.
2 parents cd16937 + 9515f0c commit b0db123

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/conviso/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.5
1+
0.3.6

src/conviso/commands/projects.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,38 @@ def _fetch_page(page_num: int):
206206
typer.echo("⚠️ No projects found.")
207207
raise typer.Exit()
208208

209+
if fetch_all:
210+
disp_page, disp_total_pages = 1, 1
211+
total = len(rows)
212+
start, end = (1, total) if total > 0 else (0, 0)
213+
else:
214+
disp_page = page
215+
disp_total_pages = total_pages or '?'
216+
total = total_count or len(rows)
217+
effective_limit = max(limit, 1)
218+
start = (page - 1) * effective_limit + 1 if total > 0 else 0
219+
end = min(page * effective_limit, total)
220+
209221
export_data(
210222
rows,
211223
schema=schema,
212224
fmt=fmt,
213225
output=output,
214-
title=f"Projects (Company {company_id}) - Page {page}/{total_pages or '?'}",
226+
title=f"Projects (Company {company_id}) - Page {disp_page}/{disp_total_pages}",
215227
)
216228

217229
if fmt != "json":
218-
total = total_count or len(rows)
219-
effective_limit = max(limit, 1)
220-
221-
start = (page - 1) * effective_limit + 1 if total > 0 else 0
222-
end = min(page * effective_limit, total)
223-
224-
total_pages_calc = math.ceil(total / effective_limit)
230+
if not fetch_all and disp_total_pages != '?':
231+
total_pages_calc = disp_total_pages
232+
elif fetch_all:
233+
total_pages_calc = 1
234+
else:
235+
total_pages_calc = math.ceil(total / max(limit, 1))
225236

226237
elapsed = time.perf_counter() - started_at
227238
timed_summary(
228239
f"Showing {start}-{end} of {total} "
229-
f"(page {page}/{total_pages_calc})",
240+
f"(page {disp_page}/{total_pages_calc})",
230241
elapsed,
231242
)
232243

0 commit comments

Comments
 (0)