You've already forked AstralRinth
forked from xxxOFFxxx/AstralRinth
Fix payout notifications (#4707)
* Add limit to payouts_values_notifications synchronizer * Set payout notification threshold to $1 * Fix formatting * Query cache
This commit is contained in:
committed by
GitHub
parent
1bad1a57b0
commit
7437a833ef
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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[..],
|
||||
|
||||
@@ -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?;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -1355,6 +1355,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?;
|
||||
|
||||
Reference in New Issue
Block a user