fix: add interval to uses of useNow so that it uses less resources #3255

Merged
dpschen merged 6 commits from feature/add-interval-to-use-now into main 2023-03-24 23:30:29 +00:00
1 changed files with 2 additions and 2 deletions
Showing only changes of commit 17cf07140f - Show all commits

View File

@ -4,10 +4,10 @@ import { useNow } from '@vueuse/core'
import LogoFull from '@/assets/logo-full.svg?component'
import LogoFullPride from '@/assets/logo-full-pride.svg?component'
import {MILLISECONDS_A_DAY} from '@/constants/date'
import {MILLISECONDS_A_HOUR} from '@/constants/date'
const now = useNow({
konrad marked this conversation as resolved
Review

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?

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?
Review

Calculating how much time left until the point of change + setTimeout (possibly setInterval in case the page is not reloaded for months) should work.

Calculating how much time left until the point of change + `setTimeout` (possibly `setInterval` in case the page is not reloaded for months) should work.
Review

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.

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.
Review

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.
Review

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.
Review

We should use the time unit constants for this.

Done!

> We should use the time unit constants for this. Done!
Review

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.

and done!

> 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. and done!
interval: MILLISECONDS_A_DAY,
interval: MILLISECONDS_A_HOUR,
})
const Logo = computed(() => now.value.getMonth() === 5 ? LogoFullPride : LogoFull)
</script>