-
Notifications
You must be signed in to change notification settings - Fork 278
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
Synchronize Google profile data (name, avatar) on a regular basis #6003
Comments
@aaemnnosttv Do you think two hours is too aggressive for profile data refreshes? Or not aggressive enough? I don't want to make too many requests, but having up-to-date info relatively close to when the user updates it is nice UX… |
As a regular cron, we're limited to the intervals that are defined in
A few ideas about how we might do this:
|
That makes sense… I think requesting it on the dashboard (eg. choice 1) makes the most sense, as it would be nice if this data was reflected the UI without too much delay—my concern with the WP sign-in or even the token refresh is that a user might update their info and then not see the effects in the Site Kit dashboard for hours or even days. Let's go with the Dashboard Refresh; I've updated the ACs—does that sound good for now? |
I don't think we should request this on every visit to the dashboard, and we also shouldn't make the request during the page load. Maybe that's not what you had in mind either, but my idea for that strategy was more to refresh the profile data from a request invoked by the client (perhaps throttled by a cached request TTL).
Access tokens only last for an hour after which they're refreshed on-demand so it wouldn't be out of date for longer than an hour. I don't think we should be overly concerned with this being out of sync as the most critical part (the email address) can't be changed without first disconnecting, so that part would always be accurate. The rest of the profile data is non-critical so keeping it up to date in a timely manner is more of a nice-to-have. We've never updated it after the initial connection before so this is a big enhancement in that regard already 😄 I still feel WP sign-in would be a good trigger for this as everyone needs to sign-in before they can get to the SK dashboard and this should be infrequent enough to avoid hitting the API too often. DetailsIn this case the action should only schedule the one-off background event though just like the fallback case in The benefit of using a client side request is that the profile data would update and the user would see the latest data more/less right away. The downside is that I think this data would rarely change to make use of that benefit and so 99% of the requests would be unnecessary. The latter holds true for the WP login strategy too, there would just be much fewer. |
@tofumatt Following up on this one, thank you! |
If we tie the event to WordPress login, the user data effectively won't ever change for a user who has the "Remember me" checkbox selected though. I definitely have some WordPress sites I basically log into once when I'm on a new device and then that's it 😅 Of the options, I think "Options 3", eg hooking it on Ad I've written ACs with that in mind, let me know what you think @aaemnnosttv. |
This choice only extends the login session validity from 2 days to 14 (ref).
Sounds good to me, I like the idea of adding a rate limit to it, that makes it sound a bit more sensible 👍 AC 👍 I'm going to downgrade this from a P0 though since the display name updates have already been released for a while now and this hasn't raised any support issues AFAIK. |
@aaemnnosttv @tofumatt What do you folks think of storing when the profile was last updated in the profile data itself, e.g. with a The other alternative could be using a transient to store the time, but I think the former is simpler. Thoughts? |
Great suggestion, thanks @nfmohit! IB ✅ |
…ofile-data Regularly sync Google profile data
QA Update ✅
|
Bug Description
Currently we don't refresh a user's profile data in the background unless there was an error with a profile data request (see: #6002 (comment)). This has two issues:
full_name
property), they won't ever be added to the profile info.To fix this, we should schedule a task that updates the user's profile info, perhaps every few hours so it doesn't feel stale after a Google profile change or new feature being added.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
wp_googlesitekit_profile
) should be updated whenever thegooglesitekit_reauthorize_user
action runs and succeeds, if their profile data hasn't been updated in the past 24 hours.Implementation Brief
includes/Core/Authentication/Clients/OAuth_Client.php
:refresh_profile_data
method:$this->profile->set()
method is called, add alast_updated
key with the value of the current UNIX timestamp (using thetime()
function).includes/Core/Authentication/Authentication.php
:register
method:googlesitekit_reauthorize_user
with a callback function doing the following:$this->profile->get()
method), check thelast_updated
key value.time() - $profile_data['last_updated']
) and see if the diffence is more than 24 hours (DAY_IN_SECONDS
).$this->get_oauth_client()->refresh_profile_data()
method with a 30 minutes$retry_after
value.Test Coverage
tests/phpunit/integration/Core/Authentication/Clients/OAuth_ClientTest.php
:refresh_profile_data
to reflect the above changes.tests/phpunit/integration/Core/Authentication/AuthenticationTest.php
:register
to reflect the above changes.QA Brief
Changelog entry
The text was updated successfully, but these errors were encountered: