Skip to content
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

Cache hasAvatar info in sessionStorage to avoid flicker #1457

Merged
merged 2 commits into from
Oct 19, 2020

Conversation

PVince81
Copy link
Contributor

This is a crude POC that shows that when we save the "does this user has an avatar call", performance improves.

Possible solution for nextcloud/spreed#4284

Maybe this should be stored in a store or something, but as I understand, Vue components in the library don't really have a store available.

Another approach would be to supply an optional property "hasAvatar" and the caching could be done from the outside in situations where the caller thinks it makes sense.

@PVince81
Copy link
Contributor Author

Any thoughts on this approach ? @ma12-co @nickvergessen @skjnldsv

If we are fine caching this information, where would be a better place ? Ideally that info should be available to other components as well like the VideoBackground in the Talk app which uses another separate query to get the avatar to put into the background in blur mode.

@@ -466,17 +466,35 @@ export default {
urlGenerator(this.user, this.size * 4) + ' 4x',
].join(', ')

// skip loading
if (!window.userHasAvatar) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use browserstorage instead? Also helps cross tabs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are cleaning the window over the last nc releases, we should try our best not to pollute the window namespace anymore :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we were to store information available for all apps, where would that be ?

in the past it used to be in the OC namespace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

browserstorage is good enough I think, or localstorage if you want 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sounds good.

will likely also need some form of expiration, but I'm not sure if worth it as the use case would be that someone deletes their avatar and do not set a new one, which is rather rare

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll go with sessionStorage. It only lives within the current page and should be enough for the use case: preventing flickering within a call session.

Then it's easier to tell people to force refresh the page than clear cache whenever they noticed that an avatar of a collegue did not get updated.

@PVince81 PVince81 marked this pull request as ready for review October 15, 2020 12:46
@PVince81
Copy link
Contributor Author

Ready to review.

Note: I went for the format "userHasAvatar-" + userId instead of a single object to avoid repeated serialization/deserialization (also semi-concurrently)

@PVince81
Copy link
Contributor Author

Weird, I just checked the browser console and somehow nothing appears under sessionStorage.

and also somehow I didn't see flickering any more. I don't understand how it can be working.

investigating...

@PVince81
Copy link
Contributor Author

ok got it... null is returned by the sessionStorage instead of undefined, which the current logic treats as always true... so no flickering...

@skjnldsv skjnldsv added 3. to review Waiting for reviews enhancement New feature or request feature: avatar Related to the avatar component and removed 2. developing Work in progress labels Oct 15, 2020
Improve performance by saving repeated HTTP calls when retrieving
information whether a user has an avatar set. Note that even HTTP calls
that hit the cache cause a delay.

This is useful to avoid flickering when switching/re-rendering vue
components that render avatars.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
@PVince81
Copy link
Contributor Author

works nicely with Chrome, but in Firefox I still observe a flicker sometimes when hitting "stop following", despite cache hit.

let's still move forward with this as it at least helps resolve the annoying flicker on speaker change, which is already a big step forward

@PVince81 PVince81 changed the title POC cache hasAvatar Cache hasAvatar info in sessionStorage to avoid flicker Oct 15, 2020
Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Oct 16, 2020
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
@PVince81
Copy link
Contributor Author

adjusted in 7613d44

I decided against introduce a service for just this once single occurrence, considering that there are no services in nextcloud-vue. If this becomes commonplace later on we could adjust.

Please also check nextcloud/spreed#4379 (last commit) which uses the same storage location for the video background.

@PVince81 PVince81 added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Oct 16, 2020
@PVince81
Copy link
Contributor Author

good to merge ? 😄

@PVince81 PVince81 merged commit 141a716 into master Oct 19, 2020
@PVince81 PVince81 deleted the poc-cache-hasavatar branch October 19, 2020 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request feature: avatar Related to the avatar component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants