mirror of
https://github.com/knadh/listmonk.git
synced 2025-09-14 10:25:46 +08:00
Fix broken sorting lists by subscriber_count
. Closes #2151.
This commit is contained in:
parent
7bfbd6a856
commit
5c0de6ef0b
3 changed files with 5 additions and 9 deletions
|
@ -62,11 +62,6 @@ func (c *Core) QueryLists(searchStr, typ, optin string, tags []string, orderBy,
|
|||
if l.Tags == nil {
|
||||
out[i].Tags = []string{}
|
||||
}
|
||||
|
||||
// Total counts.
|
||||
for _, c := range l.SubscriberCounts {
|
||||
out[i].SubscriberCount += c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -293,7 +293,7 @@ type List struct {
|
|||
Optin string `db:"optin" json:"optin"`
|
||||
Tags pq.StringArray `db:"tags" json:"tags"`
|
||||
Description string `db:"description" json:"description"`
|
||||
SubscriberCount int `db:"-" json:"subscriber_count"`
|
||||
SubscriberCount int `db:"subscriber_count" json:"subscriber_count"`
|
||||
SubscriberCounts StringIntMap `db:"subscriber_statuses" json:"subscriber_statuses"`
|
||||
SubscriberID int `db:"subscriber_id" json:"-"`
|
||||
|
||||
|
|
|
@ -432,7 +432,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
|
||||
SELECT COUNT(*) OVER () AS total, lists.* FROM lists WHERE
|
||||
CASE
|
||||
WHEN $1 > 0 THEN id = $1
|
||||
WHEN $2 != '' THEN uuid = $2::UUID
|
||||
|
@ -451,11 +451,12 @@ WITH ls AS (
|
|||
statuses AS (
|
||||
SELECT
|
||||
list_id,
|
||||
COALESCE(JSONB_OBJECT_AGG(status, subscriber_count) FILTER (WHERE status IS NOT NULL), '{}') AS subscriber_statuses
|
||||
COALESCE(JSONB_OBJECT_AGG(status, subscriber_count) FILTER (WHERE status IS NOT NULL), '{}') AS subscriber_statuses,
|
||||
SUM(subscriber_count) AS subscriber_count
|
||||
FROM mat_list_subscriber_stats
|
||||
GROUP BY list_id
|
||||
)
|
||||
SELECT ls.*, COALESCE(ss.subscriber_statuses, '{}') AS subscriber_statuses
|
||||
SELECT ls.*, COALESCE(ss.subscriber_statuses, '{}') AS subscriber_statuses, COALESCE(ss.subscriber_count, 0) AS subscriber_count
|
||||
FROM ls LEFT JOIN statuses ss ON (ls.id = ss.list_id) ORDER BY %order%;
|
||||
|
||||
-- name: get-lists-by-optin
|
||||
|
|
Loading…
Add table
Reference in a new issue