Skip to content

Commit

Permalink
Fix pagination query.
Browse files Browse the repository at this point in the history
- Fix '?per_page=all' not working inconditional LIMIT queries.
- Fetch all lists on the UI for list dropdowns everywhere.
  • Loading branch information
knadh committed Jun 4, 2021
1 parent bbffbbc commit 3d26366
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion frontend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ export const getDashboardCharts = () => http.get('/api/dashboard/charts',

// Lists.
export const getLists = (params) => http.get('/api/lists',
{ params, loading: models.lists, store: models.lists });
{
params: (!params ? { per_page: 'all' } : params),
loading: models.lists,
store: models.lists,
});

export const createList = (data) => http.post('/api/lists', data,
{ loading: models.lists });
Expand Down
8 changes: 4 additions & 4 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ SELECT COUNT(*) OVER () AS total, subscribers.* FROM subscribers
)
WHERE subscriber_lists.list_id = ALL($1::INT[])
%s
ORDER BY %s %s OFFSET $2 LIMIT $3;
ORDER BY %s %s OFFSET $2 LIMIT (CASE WHEN $3 = 0 THEN NULL ELSE $3 END);

-- name: query-subscribers-for-export
-- raw: true
Expand All @@ -258,7 +258,7 @@ SELECT s.id, s.uuid, s.email, s.name, s.status, s.attribs, s.created_at, s.updat
)
WHERE sl.list_id = ALL($1::INT[]) AND id > $2
%s
ORDER BY s.id ASC LIMIT $3;
ORDER BY s.id ASC LIMIT (CASE WHEN $3 = 0 THEN NULL ELSE $3 END);

-- name: query-subscribers-template
-- raw: true
Expand Down Expand Up @@ -321,7 +321,7 @@ SELECT * FROM lists WHERE (CASE WHEN $1 = '' THEN 1=1 ELSE type=$1::list_type EN
-- name: query-lists
WITH ls AS (
SELECT COUNT(*) OVER () AS total, lists.* FROM lists
WHERE ($1 = 0 OR id = $1) OFFSET $2 LIMIT $3
WHERE ($1 = 0 OR id = $1) OFFSET $2 LIMIT (CASE WHEN $3 = 0 THEN NULL ELSE $3 END)
),
counts AS (
SELECT COUNT(*) as subscriber_count, list_id FROM subscriber_lists WHERE status != 'unsubscribed' GROUP BY list_id
Expand Down Expand Up @@ -417,7 +417,7 @@ FROM campaigns c
WHERE ($1 = 0 OR id = $1)
AND status=ANY(CASE WHEN ARRAY_LENGTH($2::campaign_status[], 1) != 0 THEN $2::campaign_status[] ELSE ARRAY[status] END)
AND ($3 = '' OR CONCAT(name, subject) ILIKE $3)
ORDER BY %s %s OFFSET $4 LIMIT $5;
ORDER BY %s %s OFFSET $4 LIMIT (CASE WHEN $5 = 0 THEN NULL ELSE $5 END);

-- name: get-campaign
SELECT campaigns.*,
Expand Down

0 comments on commit 3d26366

Please sign in to comment.