use indices to query growth
This commit is contained in:
parent
2a4e5a0617
commit
c3892d8a25
@ -43,6 +43,15 @@ function withClause (when) {
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACKY AF this is a performance enhancement that allows us to use the created_at indices on tables
|
||||||
|
function intervalClause (when, table, and) {
|
||||||
|
if (when === 'forever') {
|
||||||
|
return and ? '' : 'TRUE'
|
||||||
|
}
|
||||||
|
|
||||||
|
return `"${table}".created_at >= now_utc() - interval '${interval(when)}' ${and ? 'AND' : ''} `
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
registrationGrowth: async (parent, { when }, { models }) => {
|
registrationGrowth: async (parent, { when }, { models }) => {
|
||||||
@ -53,7 +62,7 @@ export default {
|
|||||||
json_build_object('name', 'organic', 'value', count(users.id) FILTER(WHERE id > ${PLACEHOLDERS_NUM}) - count("inviteId"))
|
json_build_object('name', 'organic', 'value', count(users.id) FILTER(WHERE id > ${PLACEHOLDERS_NUM}) - count("inviteId"))
|
||||||
) AS data
|
) AS data
|
||||||
FROM times
|
FROM times
|
||||||
LEFT JOIN users ON time = date_trunc('${timeUnit(when)}', created_at)
|
LEFT JOIN users ON ${intervalClause(when, 'users', true)} time = date_trunc('${timeUnit(when)}', created_at)
|
||||||
GROUP BY time
|
GROUP BY time
|
||||||
ORDER BY time ASC`)
|
ORDER BY time ASC`)
|
||||||
},
|
},
|
||||||
@ -64,7 +73,7 @@ export default {
|
|||||||
json_build_object('name', 'spenders', 'value', count(DISTINCT "userId"))
|
json_build_object('name', 'spenders', 'value', count(DISTINCT "userId"))
|
||||||
) AS data
|
) AS data
|
||||||
FROM times
|
FROM times
|
||||||
LEFT JOIN "ItemAct" ON time = date_trunc('${timeUnit(when)}', created_at)
|
LEFT JOIN "ItemAct" ON ${intervalClause(when, 'ItemAct', true)} time = date_trunc('${timeUnit(when)}', created_at)
|
||||||
GROUP BY time
|
GROUP BY time
|
||||||
ORDER BY time ASC`)
|
ORDER BY time ASC`)
|
||||||
},
|
},
|
||||||
@ -77,7 +86,7 @@ export default {
|
|||||||
json_build_object('name', 'posts', 'value', count("Item".id)-count("parentId")-count("subName"))
|
json_build_object('name', 'posts', 'value', count("Item".id)-count("parentId")-count("subName"))
|
||||||
) AS data
|
) AS data
|
||||||
FROM times
|
FROM times
|
||||||
LEFT JOIN "Item" ON time = date_trunc('${timeUnit(when)}', created_at)
|
LEFT JOIN "Item" ON ${intervalClause(when, 'Item', true)} time = date_trunc('${timeUnit(when)}', created_at)
|
||||||
GROUP BY time
|
GROUP BY time
|
||||||
ORDER BY time ASC`)
|
ORDER BY time ASC`)
|
||||||
},
|
},
|
||||||
@ -91,7 +100,7 @@ export default {
|
|||||||
json_build_object('name', 'tips', 'value', coalesce(floor(sum(CASE WHEN act = 'TIP' THEN "ItemAct".msats ELSE 0 END)/1000),0))
|
json_build_object('name', 'tips', 'value', coalesce(floor(sum(CASE WHEN act = 'TIP' THEN "ItemAct".msats ELSE 0 END)/1000),0))
|
||||||
) AS data
|
) AS data
|
||||||
FROM times
|
FROM times
|
||||||
LEFT JOIN "ItemAct" ON time = date_trunc('${timeUnit(when)}', created_at)
|
LEFT JOIN "ItemAct" ON ${intervalClause(when, 'ItemAct', true)} time = date_trunc('${timeUnit(when)}', created_at)
|
||||||
JOIN "Item" ON "ItemAct"."itemId" = "Item".id
|
JOIN "Item" ON "ItemAct"."itemId" = "Item".id
|
||||||
GROUP BY time
|
GROUP BY time
|
||||||
ORDER BY time ASC`)
|
ORDER BY time ASC`)
|
||||||
@ -107,10 +116,11 @@ export default {
|
|||||||
((SELECT "ItemAct".created_at, "Item"."userId" as user_id
|
((SELECT "ItemAct".created_at, "Item"."userId" as user_id
|
||||||
FROM "ItemAct"
|
FROM "ItemAct"
|
||||||
JOIN "Item" on "ItemAct"."itemId" = "Item".id
|
JOIN "Item" on "ItemAct"."itemId" = "Item".id
|
||||||
WHERE "ItemAct".act = 'TIP')
|
WHERE ${intervalClause(when, 'ItemAct', true)} "ItemAct".act = 'TIP')
|
||||||
UNION ALL
|
UNION ALL
|
||||||
(SELECT created_at, "userId" as user_id
|
(SELECT created_at, "userId" as user_id
|
||||||
FROM "Earn")) u ON time = date_trunc('${timeUnit(when)}', u.created_at)
|
FROM "Earn"
|
||||||
|
WHERE ${intervalClause(when, 'Earn', false)})) u ON time = date_trunc('${timeUnit(when)}', u.created_at)
|
||||||
GROUP BY time
|
GROUP BY time
|
||||||
ORDER BY time ASC`)
|
ORDER BY time ASC`)
|
||||||
},
|
},
|
||||||
@ -129,10 +139,11 @@ export default {
|
|||||||
CASE WHEN "Item"."parentId" IS NULL THEN "ItemAct".msats ELSE 0 END as post
|
CASE WHEN "Item"."parentId" IS NULL THEN "ItemAct".msats ELSE 0 END as post
|
||||||
FROM "ItemAct"
|
FROM "ItemAct"
|
||||||
JOIN "Item" on "ItemAct"."itemId" = "Item".id
|
JOIN "Item" on "ItemAct"."itemId" = "Item".id
|
||||||
WHERE "ItemAct".act = 'TIP')
|
WHERE ${intervalClause(when, 'ItemAct', true)} "ItemAct".act = 'TIP')
|
||||||
UNION ALL
|
UNION ALL
|
||||||
(SELECT created_at, msats as airdrop, 0 as post, 0 as comment
|
(SELECT created_at, msats as airdrop, 0 as post, 0 as comment
|
||||||
FROM "Earn")) u ON time = date_trunc('${timeUnit(when)}', u.created_at)
|
FROM "Earn"
|
||||||
|
WHERE ${intervalClause(when, 'Earn', false)})) u ON time = date_trunc('${timeUnit(when)}', u.created_at)
|
||||||
GROUP BY time
|
GROUP BY time
|
||||||
ORDER BY time ASC`)
|
ORDER BY time ASC`)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user