fix: add interval to uses of useNow so that it uses less resources #3255
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
4 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#3255
Loading…
Reference in New Issue
No description provided.
Delete Branch "feature/add-interval-to-use-now"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Resolves vikunja/api#1434
@WofWca can you check if this fixes it?
Hi konrad!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://3255-feature-add-interval-to-use-now--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
Shouldn't the speed impact be solved by using an interval of a second? This way the time is almost up to date. The time to calculate should be neglectible. Regardless:
requestanimationframe
is supposed to be quite efficient. It would interest me why this would have a large impact on our performance.@ -7,2 +7,3 @@
const now = useNow()
const now = useNow({
interval: 24 * 60 * 60 * 1000, // Every day
We want that the Logo changes at midnight, correct? By setting this to change in an interval of a day this might happen at 23:00 the next day if the logo page with the logo was opened at that time the day before. Could we configure this somehow so that it's triggered every real daychange? Or hour change?
Calculating how much time left until the point of change +
setTimeout
(possiblysetInterval
in case the page is not reloaded for months) should work.Ideally we want to change the logo at midnight, yes. But since this is not something I'd consider critical and it will be shown for a whole month it should be enough to check this once a day. Even if that means it might lag behind one day.
We should use the time unit constants for this.
How about using every hour? One tick per hour should really not create any performance issues (as said earlier I think once per second should also not be an issue.
We should use the time unit constants for this.
How about using every hour? One tick per hour should really not create any performance issues (as said earlier I think once per second should also not be an issue.
Done!
and done!
@ -159,2 +159,3 @@
const today = useNow()
const today = useNow({
interval: 6 * 60 * 60 * 1000, // Every 6 hours
If we don't change this constantly I think it would be better to only change it when the user switches view. Changing it every 6 hours seems random in comparison.
That's a good point.
Done!
@ -11,2 +11,3 @@
const {t} = useI18n({useScope: 'global'})
const now = useNow()
const now = useNow({
interval: 30 * 60 * 1000, // Every 30 minutes
Same here.
Done!
Yes, it's better.
@ -159,2 +158,3 @@
const today = useNow()
const today = ref(new Date())
onMounted(() => today.value = new Date())
I think it should be
onActivated
Because it the view is cached mounted will not trigger again.
Ah yes, good point. Fixed.
@ -11,2 +10,3 @@
const {t} = useI18n({useScope: 'global'})
const now = useNow()
const now = ref(new Date())
onMounted(() => now.value = new Date())
Same here
Done.