From 73ce11463290957cff2bed8de7697ea152c58a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-X=2E=20T?= Date: Mon, 3 Nov 2025 14:50:04 -0500 Subject: [PATCH 1/4] Add limit to payouts_values_notifications synchronizer --- .../src/database/models/payouts_values_notifications.rs | 3 +++ apps/labrinth/src/queue/payouts.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/apps/labrinth/src/database/models/payouts_values_notifications.rs b/apps/labrinth/src/database/models/payouts_values_notifications.rs index 0483d2abc4..12dbf3f9e8 100644 --- a/apps/labrinth/src/database/models/payouts_values_notifications.rs +++ b/apps/labrinth/src/database/models/payouts_values_notifications.rs @@ -56,6 +56,7 @@ impl PayoutsValuesNotification { pub async fn synchronize_future_payout_values( exec: impl sqlx::PgExecutor<'_>, + limit: i64, ) -> Result<(), DatabaseError> { sqlx::query!( " @@ -63,8 +64,10 @@ pub async fn synchronize_future_payout_values( SELECT DISTINCT date_available, user_id, false notified FROM payouts_values WHERE date_available > NOW() + LIMIT $1 ON CONFLICT (date_available, user_id) DO NOTHING ", + limit, ) .execute(exec) .await?; diff --git a/apps/labrinth/src/queue/payouts.rs b/apps/labrinth/src/queue/payouts.rs index 88feaaea28..be6764ece8 100644 --- a/apps/labrinth/src/queue/payouts.rs +++ b/apps/labrinth/src/queue/payouts.rs @@ -1097,6 +1097,7 @@ pub async fn index_payouts_notifications( payouts_values_notifications::synchronize_future_payout_values( &mut *transaction, + 200, ) .await?; let items = payouts_values_notifications::PayoutsValuesNotification::unnotified_users_with_available_payouts_with_limit(&mut *transaction, 200).await?; From e5d1142b8612b8bc75e7cdad370add5dff1b983f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-X=2E=20T?= Date: Mon, 3 Nov 2025 14:51:02 -0500 Subject: [PATCH 2/4] Set payout notification threshold to $1 --- apps/labrinth/src/database/models/notification_item.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/labrinth/src/database/models/notification_item.rs b/apps/labrinth/src/database/models/notification_item.rs index aad147844f..bf3d5e7d10 100644 --- a/apps/labrinth/src/database/models/notification_item.rs +++ b/apps/labrinth/src/database/models/notification_item.rs @@ -81,7 +81,7 @@ impl NotificationBuilder { 'amount', to_jsonb(sum) ) body FROM period_payouts - WHERE sum > 0 + WHERE sum >= 100 ", ¬ification_ids[..], &users_raw_ids[..], From 64e3700171f87181fc2af15b7d58dabcd20128e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-X=2E=20T?= Date: Mon, 3 Nov 2025 15:06:36 -0500 Subject: [PATCH 3/4] Fix formatting --- apps/labrinth/src/queue/email/templates.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/labrinth/src/queue/email/templates.rs b/apps/labrinth/src/queue/email/templates.rs index c2234fef13..dafcd15b2a 100644 --- a/apps/labrinth/src/queue/email/templates.rs +++ b/apps/labrinth/src/queue/email/templates.rs @@ -631,7 +631,7 @@ async fn collect_template_variables( map.insert( PAYOUTAVAILABLE_AMOUNT, - format!("USD${:.2}", *amount as f64 / 100.0), + format!("${:.2} USD", *amount as f64 / 100.0), ); Ok(EmailTemplate::Static(map)) From 64edc34408bc65c57218fedf037f6fc6fe043487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-X=2E=20T?= Date: Mon, 3 Nov 2025 15:08:00 -0500 Subject: [PATCH 4/4] Query cache --- ...c6dfc60c93c6cecf947c2f96b43926ce5147c4aafe9089cd.json} | 4 ++-- ...107b3ffaef3f153b01c2f9d8b14a0fa8078cfd908aa3255f.json} | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) rename apps/labrinth/.sqlx/{query-7910f8c982de4c9c8f3b40cecda741d6d43c3084b7f347e5da31c353cc9bae53.json => query-807d42d4aab8312fc6dfc60c93c6cecf947c2f96b43926ce5147c4aafe9089cd.json} (89%) rename apps/labrinth/.sqlx/{query-603c1109f8c5a9a5b45b3f531fcb6b597ac01c831fbbcb296fc5ba08cc622482.json => query-ba8b07d9cd62d9ec107b3ffaef3f153b01c2f9d8b14a0fa8078cfd908aa3255f.json} (58%) diff --git a/apps/labrinth/.sqlx/query-7910f8c982de4c9c8f3b40cecda741d6d43c3084b7f347e5da31c353cc9bae53.json b/apps/labrinth/.sqlx/query-807d42d4aab8312fc6dfc60c93c6cecf947c2f96b43926ce5147c4aafe9089cd.json similarity index 89% rename from apps/labrinth/.sqlx/query-7910f8c982de4c9c8f3b40cecda741d6d43c3084b7f347e5da31c353cc9bae53.json rename to apps/labrinth/.sqlx/query-807d42d4aab8312fc6dfc60c93c6cecf947c2f96b43926ce5147c4aafe9089cd.json index d245c5434b..9380c69df1 100644 --- a/apps/labrinth/.sqlx/query-7910f8c982de4c9c8f3b40cecda741d6d43c3084b7f347e5da31c353cc9bae53.json +++ b/apps/labrinth/.sqlx/query-807d42d4aab8312fc6dfc60c93c6cecf947c2f96b43926ce5147c4aafe9089cd.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n WITH\n period_payouts AS (\n SELECT\n ids.notification_id,\n ids.user_id,\n ids.date_available,\n FLOOR(COALESCE(SUM(pv.amount), 0.0) * 100) :: BIGINT sum -- Convert to cents\n FROM UNNEST($1::bigint[], $2::bigint[], $3::timestamptz[]) AS ids(notification_id, user_id, date_available)\n LEFT JOIN payouts_values pv ON pv.user_id = ids.user_id AND pv.date_available = ids.date_available\n GROUP BY ids.user_id, ids.notification_id, ids.date_available\n )\n INSERT INTO notifications (\n id, user_id, body\n )\n SELECT\n notification_id id,\n user_id,\n JSONB_BUILD_OBJECT(\n 'type', 'payout_available',\n 'date_available', to_jsonb(date_available),\n 'amount', to_jsonb(sum)\n ) body\n FROM period_payouts\n WHERE sum > 0\n ", + "query": "\n WITH\n period_payouts AS (\n SELECT\n ids.notification_id,\n ids.user_id,\n ids.date_available,\n FLOOR(COALESCE(SUM(pv.amount), 0.0) * 100) :: BIGINT sum -- Convert to cents\n FROM UNNEST($1::bigint[], $2::bigint[], $3::timestamptz[]) AS ids(notification_id, user_id, date_available)\n LEFT JOIN payouts_values pv ON pv.user_id = ids.user_id AND pv.date_available = ids.date_available\n GROUP BY ids.user_id, ids.notification_id, ids.date_available\n )\n INSERT INTO notifications (\n id, user_id, body\n )\n SELECT\n notification_id id,\n user_id,\n JSONB_BUILD_OBJECT(\n 'type', 'payout_available',\n 'date_available', to_jsonb(date_available),\n 'amount', to_jsonb(sum)\n ) body\n FROM period_payouts\n WHERE sum >= 100\n ", "describe": { "columns": [], "parameters": { @@ -12,5 +12,5 @@ }, "nullable": [] }, - "hash": "7910f8c982de4c9c8f3b40cecda741d6d43c3084b7f347e5da31c353cc9bae53" + "hash": "807d42d4aab8312fc6dfc60c93c6cecf947c2f96b43926ce5147c4aafe9089cd" } diff --git a/apps/labrinth/.sqlx/query-603c1109f8c5a9a5b45b3f531fcb6b597ac01c831fbbcb296fc5ba08cc622482.json b/apps/labrinth/.sqlx/query-ba8b07d9cd62d9ec107b3ffaef3f153b01c2f9d8b14a0fa8078cfd908aa3255f.json similarity index 58% rename from apps/labrinth/.sqlx/query-603c1109f8c5a9a5b45b3f531fcb6b597ac01c831fbbcb296fc5ba08cc622482.json rename to apps/labrinth/.sqlx/query-ba8b07d9cd62d9ec107b3ffaef3f153b01c2f9d8b14a0fa8078cfd908aa3255f.json index 3d0c4126eb..d2ccf628b3 100644 --- a/apps/labrinth/.sqlx/query-603c1109f8c5a9a5b45b3f531fcb6b597ac01c831fbbcb296fc5ba08cc622482.json +++ b/apps/labrinth/.sqlx/query-ba8b07d9cd62d9ec107b3ffaef3f153b01c2f9d8b14a0fa8078cfd908aa3255f.json @@ -1,12 +1,14 @@ { "db_name": "PostgreSQL", - "query": "\n\t\tINSERT INTO payouts_values_notifications (date_available, user_id, notified)\n\t\tSELECT DISTINCT date_available, user_id, false notified\n\t\tFROM payouts_values\n\t\tWHERE date_available > NOW()\n\t\tON CONFLICT (date_available, user_id) DO NOTHING\n\t\t", + "query": "\n\t\tINSERT INTO payouts_values_notifications (date_available, user_id, notified)\n\t\tSELECT DISTINCT date_available, user_id, false notified\n\t\tFROM payouts_values\n\t\tWHERE date_available > NOW()\n\t\tLIMIT $1\n\t\tON CONFLICT (date_available, user_id) DO NOTHING\n\t\t", "describe": { "columns": [], "parameters": { - "Left": [] + "Left": [ + "Int8" + ] }, "nullable": [] }, - "hash": "603c1109f8c5a9a5b45b3f531fcb6b597ac01c831fbbcb296fc5ba08cc622482" + "hash": "ba8b07d9cd62d9ec107b3ffaef3f153b01c2f9d8b14a0fa8078cfd908aa3255f" }