-
Notifications
You must be signed in to change notification settings - Fork 271
feat: adjust background sync on user activity #11149
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
base: main
Are you sure you want to change the base?
Conversation
4109db8
to
ae2c593
Compare
Signed-off-by: SebastianKrupinski <[email protected]>
71b55f7
to
ad65815
Compare
Signed-off-by: SebastianKrupinski <[email protected]>
95d2bca
to
ce40db2
Compare
Failing tests are unrelated, failing due to missing NCU name space interfaces in NC30 |
I doubt it ;) |
lib/BackgroundJob/SyncJob.php
Outdated
@@ -79,6 +84,12 @@ protected function run($argument) { | |||
return; | |||
} | |||
|
|||
if (($this->userConfig->getValueInt($account->getUserId(), Application::APP_ID, 'ui-hearthbeat') - $this->time->getTime()) > 900) { |
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.
if (($this->userConfig->getValueInt($account->getUserId(), Application::APP_ID, 'ui-hearthbeat') - $this->time->getTime()) > 900) { | |
if (($this->userConfig->getValueInt($account->getUserId(), Application::APP_ID, 'ui-heartbeat') - $this->time->getTime()) > 900) { |
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.
Done
@@ -140,6 +136,8 @@ public function sync(int $id, array $ids = [], ?int $lastMessageTimestamp = null | |||
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); | |||
$order = $sortOrder === 'newest' ? IMailSearch::ORDER_NEWEST_FIRST: IMailSearch::ORDER_OLDEST_FIRST; | |||
|
|||
$this->userConfig->setValueInt($this->currentUserId, Application::APP_ID, 'ui-hearthbeat', 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.
$this->userConfig->setValueInt($this->currentUserId, Application::APP_ID, 'ui-hearthbeat', time()); | |
$this->userConfig->setValueInt($this->currentUserId, Application::APP_ID, 'ui-heartbeat', 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.
Done
@@ -140,6 +136,8 @@ public function sync(int $id, array $ids = [], ?int $lastMessageTimestamp = null | |||
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); | |||
$order = $sortOrder === 'newest' ? IMailSearch::ORDER_NEWEST_FIRST: IMailSearch::ORDER_OLDEST_FIRST; | |||
|
|||
$this->userConfig->setValueInt($this->currentUserId, Application::APP_ID, 'ui-hearthbeat', 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.
$this->userConfig->setValueInt($this->currentUserId, Application::APP_ID, 'ui-hearthbeat', time()); | |
$this->userConfig->setValueInt($this->currentUserId, Application::APP_ID, 'ui-hearthbeat', time()); |
To make it testable: Replace time() with ITimeFactoy.getTime.
if (!method_exists(IManager::class, 'handleImipRequest')) { | ||
self::markTestIncomplete(); | ||
$this->assertTrue(true); |
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.
As this seems unrelated, please remove it.
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.
It is unrelated that is why it is in a separate commit. And need to fix a failing nc30 test
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.
No.
See https://github.com/nextcloud/mail/actions/runs/16008830201/job/45161666190?pr=11340 (copy of this branch, without the IMipServiceTest change => only the warning about the incomplet test is gone, but the incomplet test isn't the problem)
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.
Signed-off-by: SebastianKrupinski <[email protected]>
IUserManager $userManager, | ||
AccountService $accountService, | ||
MailboxSync $mailboxSync, | ||
ImapToDbSynchronizer $syncService, | ||
LoggerInterface $logger, | ||
IJobList $jobList, | ||
IConfig $config) { | ||
IConfig $config, | ||
private IUserConfig $userConfig, |
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.
IUserConfig is new in 31.
Use IConfig.getUserValue instread.
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.
From when we discussed the feature I remember saying that we want to track when a user accesses Mail. If they access it frequently we keep the hourly sync. If they don't, we drop down to one sync in four hours or even less often.
The current change tries to detect user activity, then skips syncing but also drops the interval from 60 minutes to 15 minutes.
Can you explain why the implementation was done so different to what we discussed? Are there new findings that make the original idea impossible?
@@ -79,6 +84,12 @@ protected function run($argument) { | |||
return; | |||
} | |||
|
|||
if (($this->userConfig->getValueInt($account->getUserId(), Application::APP_ID, 'ui-heartbeat') - $this->time->getTime()) > 900) { | |||
$this->logger->debug('Detected user activity, skipping background sync job'); | |||
$this->setInterval(900); |
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.
Does setting the interval of an already running job have any consequence?
Yes, that is what I am trying to do with this. The idea here is that the background sync will not run as long as there is a up to date heart beat. So as long as the mail UI has been active the background sync will not run, but will revert back to the regular configured interval when there is no activity. Essentially if you are active all day the background sync should not execute. And if you are not active often then it will revert to the default once an hour to sync the mailbox to reduce UI waiting time, and to pick things like iMip. It only reschdules to 15min when there is a heart beat to check for another heart beat, as the sync can be configure to run every 5min (app.mail.background-sync-interval), I thought it was more sane to check less frequently. We can probably change this to 30min. |
The cron sync will sync all INBOXes and mailboxes marked for background sync. Frontend will sync INBOXes and the currently open mailbox. Therefore, the background sync should also run when a user has the app open all day. |
Resolves
#10717
Summary