-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimizing competitor kpis #89
Conversation
…es largely the speed of the query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach looks good. However, I'd like to see if we can make the date filter a bit less ugly given that we need to add it all over the place.
on | ||
date_trunc('minute', block_time) = p0.timestamp | ||
p0.timestamp = date_trunc('day', case when ('{{end_time}}' = '2100-01-01' or date('{{end_time}}') = date_trunc('day', now())) then now() - interval '1' day else date('{{end_time}}') end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic seems unnecessarily complex. Isn't this the same as
least(date('{{end_time}}'), now() - interval '1' day)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please document the new parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed :)
and p0.timestamp >= date_add('day', -1, (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end)) | ||
and p0.timestamp <= (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe using
p0.timestamp between date_add('day', -1, least('{{competitor_end_time}}', now())) and least('{{competitor_end_time}}', now())
is slightly easier to read? Also I'm not sure if reducing the range to now()
is actually making the query more effective (since there are no datapoints beyond now the full table scan should complete in the same time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
About the now(), the query is built to only search for 24 hours, so the upper bound is meant to backfill the data base
…to end (more intuitive) as we are talking about dates
I changed the parameter from end_time to start_time, as it makes more sense when rounding to a date |
Updated the queries to fit the new table prices.minute to use them more efficiently.
For total TVL, switched to the table prices.day: less expensive and gets an average over the time frame for the study