Commit graph

168 commits

Author SHA1 Message Date
Kailash Nadh
5c0de6ef0b Fix broken sorting lists by subscriber_count. Closes #2151. 2024-12-04 22:40:13 +05:30
Kailash Nadh
178fa94880 Update user login time on password login. 2024-10-26 23:56:12 +05:30
Kailash Nadh
1e4b3a26f2 Separate get individual user and get all users queries. 2024-10-26 17:03:02 +05:30
Kailash Nadh
887d5823f4 Fix get-users query to return all users when no ID param is given. 2024-10-21 23:20:07 +05:30
Kailash Nadh
1075485ca9 Merge branch 'fix-user-query' 2024-10-21 17:57:28 +05:30
Kailash Nadh
e7109daaf3 Fix missing email validation in OIDC exchange. 2024-10-21 17:54:58 +05:30
Kailash Nadh
7847167145 Fix incorrect id logic in user selection. 2024-10-20 23:50:06 +05:30
Kailash Nadh
cea65c009d Fix and refactor subscriber batch fetching in campaign processing.
This has been a hair-pulling rabbit hole of an issue. #1931 and others.
When the `next-campaign-subscribers` query that fetches $n subscribers
per batch for a campaign returns no results, the manager assumes
that the campaign is done and marks as finished.

Marathon debugging revealed fundamental flaws in qyery's logic that
would incorrectly return 0 rows under certain conditions.
- Based on the "layout" of subscribers for eg: a series of blocklisted
  subscribers between confirmed subscribers.
  A series of unconfirmed subscribers in a batch belonging to a double
  opt-in list.
- Bulk import blocklisting users, but not marking their subscriptions
  as 'unsubscribed'.
- Conditions spread across multiple CTEs resulted in returning an
  arbitrary number of rows and $N per batch as the selected $N rows
  would get filtered out elsewhere, possibly even becoming 0.

After fixing this and testing it on our prod instance that has
15 million subscribers and ~70 million subscriptions in the
`subscriber_lists` table, ended up discovered significant inefficiences
in Postgres query planning. When `subscriber_lists` and campaign list IDs
are joined dynamically (CTE or ANY() or any kind of JOIN that involves)
a query, the Postgres query planner is unable to use the right indexes.

After testing dozens of approaches, discovered that statically passing
the values to join on (hardcoding or passing via parametrized $1 vars),
the query uses the right indexes. The difference is staggering.
For the particular scenario on our large prod DB to pull a batch,
~15 seconds vs. ~50ms, a whopping 300x improvement!

This patch splits `next-campaign-subscribers` into two separate queries,
one which fetches campaign metadata and list_ids, whose values are then
passed statically to the next query to fetch subscribers by batch.

In addition, it fixes and refactors broken filtering and counting logic
in `create-campaign` and `next-campaign` queries.

Closes #1931, #1993, #1986.
2024-10-13 17:03:59 +05:30
Kailash Nadh
ee119b0088 Fix import not 'unsubscribing' list subs for already blacklisted subscribers. Ref #1931. 2024-10-13 17:03:59 +05:30
Kailash Nadh
0331e3ce4e Sory users by created_at always. 2024-10-13 17:03:59 +05:30
Kailash Nadh
eb47e80c35 Fix list auth by adding an explicit 'getAll' flag to query. 2024-10-13 17:03:59 +05:30
Kailash Nadh
ae2a386193 Add support for "list roles".
This commit splits roles into two, user roles and list roles, both of which
are attached separately to a user.

List roles are collection of lists each with read|write permissions, while
user roles now have all permissions except for per-list ones.

This allows for easier management of roles, eliminating the need to clone and
create new roles just to adjust specific list permissions.
2024-10-13 17:03:58 +05:30
Kailash Nadh
12a6451ed0 Add list permission check to subscriber calls. 2024-10-13 17:03:55 +05:30
Kailash Nadh
d74e067961 Add per-list permission to list management.
- Filter lists by permitted list IDs in DB get calls.
- Split getLists() handlers into two (one, all) for clarity.
- Introduce new `subscribers:get_by_list` permission.
- Tweak UI rendering to work with new per-list permssions.
2024-10-13 16:59:52 +05:30
Kailash Nadh
1649b3b135 Fix logic for preventing sole super admin from being wrongly updated/deleted. 2024-10-13 16:59:52 +05:30
Kailash Nadh
5024ded763 Add API user authentication to auth module with caching of creds on user CRUD. 2024-10-13 16:59:52 +05:30
Kailash Nadh
1e875afa67 Add OIDC auth hooks (init, callback, session) and finish OIDC support. 2024-10-13 16:59:52 +05:30
Kailash Nadh
17b5cc1774 Sort roles by created date. 2024-10-13 16:59:52 +05:30
Kailash Nadh
d52eac0948 Update user APIs and queries to embed role + list permissions. 2024-10-13 16:59:52 +05:30
Kailash Nadh
612c1d6eac Add per-list permission management to roles. 2024-10-13 16:59:52 +05:30
Kailash Nadh
dd9612b1ed Add user profile based permission check in auth middleware. 2024-10-13 16:59:52 +05:30
Kailash Nadh
32d5823dfe Refactor 'super' user type to a pre-defined super admin role. 2024-10-13 16:59:52 +05:30
Kailash Nadh
d4e4c5fa99 Add granular permissions and role management to backend and admin UI. 2024-10-13 16:59:51 +05:30
Kailash Nadh
4997c10b97 Add user profile APIs and update UI. 2024-10-13 16:59:51 +05:30
Kailash Nadh
57ac9dca4b Add public login page and auth middleware and handlers. 2024-10-13 16:59:51 +05:30
Kailash Nadh
1516bf216f Add api type user. 2024-10-13 16:59:51 +05:30
Kailash Nadh
bf0b500bb0 Add API token authentication. 2024-10-13 16:59:51 +05:30
Kailash Nadh
0968e58766 Add user/password login handler. 2024-10-13 16:59:51 +05:30
Kailash Nadh
435d6d5169 Add create/add/delete user management UI and database schema. 2024-10-13 16:59:51 +05:30
Bowrna
16f4dfd3e9
Fix incorrect bulk blocklisting behaviour (#2041). Fixes #1841 2024-09-19 10:56:56 +05:30
Kailash Nadh
51e3f1789b Fix pre-confirm status not working on subscriber update. Closes #1927. 2024-09-03 23:39:02 +05:30
Bowrna
ebac8b3b4c
Fix broken campaign clone with deleted lists (#1966)
Co-authored-by: Kailash Nadh <kailash@nadh.in>
2024-08-02 21:33:43 +05:30
Keshav Gupta
c334d2e6e1
fix #1950:Export of unsubscribed users exports all users (#1965)
Co-authored-by: keshav <keshav.gupta@jarvis.consulting>
2024-08-02 00:05:33 +05:30
Kailash Nadh
fedc51514d Fix incorrect count in subscriber query when there are no results. 2024-08-02 00:03:22 +05:30
zevszym
b38f1562ee
fix vanishing attachments in campaign in more the one campaigns setup (#1936) 2024-07-17 10:42:51 +05:30
Shivam Mishra
ec50bef292
fix: query campaign does not search numbers (#1758) 2024-03-08 09:48:34 +05:30
Kailash Nadh
284158666b Fix sorting in camapaign analytics view counts. 2024-01-28 10:59:51 +05:30
Kailash Nadh
5a3664aee2 Add support for caching slow queries on large databases.
- Add materialized views for list -> subscriber counts, dashboard chart,
  and dashboard aggregate stats that slow down significantly on large
  databases (with millions or tens of millions of subscribers). These
  slow queries involve full table scan COUNTS().

- Add a toggle to enable caching slow results in Settings -> Performance.

- Add support for setting a cron string that crons and periodically
  refreshes aggregated stats in materialized views.

Closes #1019.
2024-01-27 15:51:12 +05:30
Kailash Nadh
0d319ad9fd Add 'slug' (permalink) support for campaign archives. Closes #1394. 2024-01-09 23:34:08 +05:30
Kailash Nadh
772476c0df Add accurate sent count, last sent subscriber tracking on campaigns.
- Sent count is no longer the batch size fetched from the DB but is
  the actual count of messages sent.
- Pausing and resuming now accurately tracks the last subscriber that
  was processed and resumes from there.
- Fix multiple concurrent campaigns blocking.

Closes #1616. Closes #905. Closes #1496. Closes #1250. Closes #1010.
2024-01-02 14:57:04 +05:30
Kailash Nadh
bce675870c Fix preconfirm option not working on bulk 'select all' subscriber list management. Closes #1646. 2023-12-30 20:52:14 +05:30
Kailash Nadh
51af75cfef Add subscription status filter to subscriber list query and admin UI. 2023-12-23 16:43:28 +05:30
Kailash Nadh
01acd386f6 Add tag/type/optin filter options to lists and campaigns APIs. Closes #1631. 2023-12-23 14:45:55 +05:30
Kailash Nadh
c59825f3a5 Fix broken sorting (lists -> subcount, subscribers -> status) in queries. Closes #1076. 2023-11-12 10:29:32 +05:30
Kailash Nadh
44d3462559 Fix 'confirmed' subscriptions becoming 'unconfirmed' on public form re-signup. Closes #1441. 2023-11-11 18:46:38 +05:30
Kailash Nadh
eefcbc30a3 Fix hardcoded DB name in 'about' SQL query. Closes #1477. 2023-08-27 13:20:41 +05:30
Ikko Eltociear Ashimine
a1c507b477
Fix typo in queries.sql (#1432)
defualt -> default
2023-08-06 10:06:44 +05:30
Kailash Nadh
ad80c716f9 Add new privacy option 'Record opt-in IP' to record IP address of optin confirmation.
- Add new 'Subscriptions' table on the subscriber list form that shows subs,
  IP, and other data.
- Add new `meta` JSONB field to `subscriber_lsts` table.

Closes #1329.
2023-07-26 23:00:32 +05:30
Kailash Nadh
e1c0bf5030 Fix unsubbed subscribers not getting re-sub optin confirmation. Closes #1315. 2023-07-12 23:09:44 +05:30
Kailash Nadh
c581fe2f3a Add GET /api/about that returns useful system info. Closes #1354. 2023-06-24 13:07:13 +05:30