Consider the following queries to get counts:
Query A
SELECT
COUNT(*)
FROM
"user_notifications"
WHERE
"user_notifications"."source_id" = 5196
AND "user_notifications"."source_type" = 'MassGifting'
AND "user_notifications"."status" = 'sent'
AND "user_notifications"."read_at" IS NULL
Executation details:
This takes about 6-10seconds.
Query B Its also on the same table, just where clause is slightly different, trying to check sounds of notifications based on their status, if they have been read based on source_id & source_type.:
SELECT
COUNT(*)
FROM
"user_notifications"
WHERE
"user_notifications"."source_id" = 5196
AND "user_notifications"."source_type" = 'MassGifting'
AND (
"user_notifications"."read_at" IS NOT NULL
)
Execution Details:
Time taken: 5-6seconds. In total is takes about 30-60seconds to execute these two queries & render the report on our website.
I was wondering what are the way which we can speed this up?