-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
[back][front] perf: stats API can be filtered by poll #1830
Conversation
This will reduce the amount of SQL queries when only the stats of a single poll are required.
if ( | ||
stats.polls.length === 0 || | ||
currentTime - lastRefreshAt.current >= EXPIRATION_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.
add a condition to force refresh when current poll
is not present in stats.polls
?
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.
Addressed by 9df3994
I finally opted for a ref, instead of checking if the poll was present in stats.polls
. This allows to handle the specific case where getStats
is called two times in a row in less than 4 seconds, a first time with a single poll, and a second time with no poll.
if (loading.current) { | ||
return stats; | ||
} |
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.
In some cases, this means getStats()
could return stats about the wrong poll, because a concurrent request is running. This is probably not a problem for now, as there is a single one active poll, but it would be worth adding a FIXME.
if (loading.current) { | |
return stats; | |
} | |
// FIXME: this function may return stats about the wrong poll here. | |
// Maybe `useStats()` should always depend on `useCurrentPoll()` to simplify this logic. | |
if (loading.current) { | |
return stats; | |
} |
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.
Fixed by 094f030
related issues #1829
Description
This PR adds a query parameter to the
/stats/
API that allows to retrieve the stats of a single poll, instead of all at once.Checklist