| 10 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
|
10 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, cast, \
|
| 13 |
PUSH_NOTIFICATIONS_RETRY_SQL ="select x.user_id, x.id, x.created, x.notification_campaign_id, x.name, TIMESTAMPDIFF(HOUR, x.created, x.expiresat) tdiff, x.sent-IF (y.received is null, 0, y.received) failureCount, x.last_active, x.expiresat from (select p.id,p.user_id, p.created, p.notification_campaign_id, n.name, count(*) sent, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' or name not like '%copy%')) and p.type='sent' and p.message = 'success' and ua.last_active >= p.created and ua.last_active <= n.expiresat group by p.id) as x left join (select p.id, p.user_id, p.created, p.notification_campaign_id, n.name, count(*) received, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' or name not like '%copy%')) and p.type='recieved' group by p.id) as y on (x.user_id = y.user_id and x.notification_campaign_id = y.notification_campaign_id) having failureCount =1"
|
13 |
PUSH_NOTIFICATIONS_RETRY_SQL ="select x.user_id, x.id, x.created, x.notification_campaign_id, x.name, TIMESTAMPDIFF(HOUR, x.created, x.expiresat) tdiff, x.sent-IF (y.received is null, 0, y.received) failureCount, x.last_active, x.expiresat from (select p.id,p.user_id, p.created, p.notification_campaign_id, n.name, count(*) sent, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id join (select * from (select * from devices order by id desc) dev group by user_id) d on p.user_id = d.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' and name not like '%copy%')) and p.type='sent' and p.message = 'success' and d.versioncode >=14 and ua.last_active >= p.created and ua.last_active <= n.expiresat group by p.id) as x left join (select p.id, p.user_id, p.created, p.notification_campaign_id, n.name, count(*) received, ua.last_active, n.expiresat from pushnotifications p join notification_campaigns n on p.notification_campaign_id = n.id join useractive ua on p.user_id = ua.user_id join (select * from (select * from devices order by id desc) dev group by user_id) d on p.user_id = d.user_id where p.notification_campaign_id in (select id from notification_campaigns where TIMESTAMPDIFF(HOUR, created, NOW())<=2 and (name not like 'Batch Credit%' and name not like '%copy%')) and d.versioncode >=14 and p.type='recieved' group by p.id) as y on (x.user_id = y.user_id and x.notification_campaign_id = y.notification_campaign_id) having failureCount =1"
|