Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-03-23 19:22:02 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-03-25 11:45:09 +0300
commit00ea4273322ca18746d9a21714869c47ca2a1ea0 (patch)
tree0dc1cc28c693ee0149afd8d778cfd838744b0719 /lib
parent7bc1cb1f64294236dcab0f24d4757399539c7524 (diff)
Add time check to hasLocks
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/Mailbox.php21
-rw-r--r--lib/Db/MailboxMapper.php2
-rw-r--r--lib/Db/TagMapper.php2
-rw-r--r--lib/Service/Search/MailSearch.php10
4 files changed, 27 insertions, 8 deletions
diff --git a/lib/Db/Mailbox.php b/lib/Db/Mailbox.php
index 61f56b01c..eb7ca6a2e 100644
--- a/lib/Db/Mailbox.php
+++ b/lib/Db/Mailbox.php
@@ -82,6 +82,12 @@ class Mailbox extends Entity implements JsonSerializable {
protected $specialUse;
protected $syncInBackground;
+ /**
+ * @var int
+ * Lock timeout for sync (5 minutes)
+ */
+ public const LOCK_TIMEOUT = 300;
+
public function __construct() {
$this->addType('accountId', 'integer');
$this->addType('messages', 'integer');
@@ -119,10 +125,17 @@ class Mailbox extends Entity implements JsonSerializable {
&& $this->getSyncVanishedToken() !== null;
}
- public function hasLocks(): bool {
- return $this->getSyncNewLock() !== null
- || $this->getSyncChangedLock() !== null
- || $this->getSyncVanishedLock() !== null;
+ public function hasLocks(int $now): bool {
+ if ($this->getSyncNewLock() !== null || $this->getSyncNewLock() > ($now - self::LOCK_TIMEOUT)) {
+ return true;
+ }
+ if ($this->getSyncChangedLock() !== null || $this->getSyncChangedLock() > ($now - self::LOCK_TIMEOUT)) {
+ return true;
+ }
+ if ($this->getSyncVanishedLock() !== null || $this->getSyncVanishedLock() > ($now - self::LOCK_TIMEOUT)) {
+ return true;
+ }
+ return false;
}
public function jsonSerialize() {
diff --git a/lib/Db/MailboxMapper.php b/lib/Db/MailboxMapper.php
index 4d5ee15c2..801fd64ca 100644
--- a/lib/Db/MailboxMapper.php
+++ b/lib/Db/MailboxMapper.php
@@ -148,7 +148,7 @@ class MailboxMapper extends QBMapper {
$now = $this->timeFactory->getTime();
if ($lock !== null
- && $lock > ($now - 5 * 60)) {
+ && $lock > ($now - Mailbox::LOCK_TIMEOUT)) {
// Another process is syncing
throw MailboxLockedException::from($mailbox);
}
diff --git a/lib/Db/TagMapper.php b/lib/Db/TagMapper.php
index 219590223..4ce489cc4 100644
--- a/lib/Db/TagMapper.php
+++ b/lib/Db/TagMapper.php
@@ -158,7 +158,7 @@ class TagMapper extends QBMapper {
foreach ($queryResult as $qr) {
$result[] = $qr['imap_message_id'];
$result[$qr['imap_message_id']][] = $this->getTag((int)$qr['tag_id']);
- };
+ }
return $result;
}
diff --git a/lib/Service/Search/MailSearch.php b/lib/Service/Search/MailSearch.php
index 582944c22..fc233689b 100644
--- a/lib/Service/Search/MailSearch.php
+++ b/lib/Service/Search/MailSearch.php
@@ -39,6 +39,7 @@ use OCA\Mail\Exception\ServiceException;
use OCA\Mail\IMAP\PreviewEnhancer;
use OCA\Mail\IMAP\Search\Provider as ImapSearchProvider;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IUser;
class MailSearch implements IMailSearch {
@@ -58,16 +59,21 @@ class MailSearch implements IMailSearch {
/** @var PreviewEnhancer */
private $previewEnhancer;
+ /** @var ITimeFactory */
+ private $timeFactory;
+
public function __construct(FilterStringParser $filterStringParser,
MailboxMapper $mailboxMapper,
ImapSearchProvider $imapSearchProvider,
MessageMapper $messageMapper,
- PreviewEnhancer $previewEnhancer) {
+ PreviewEnhancer $previewEnhancer,
+ ITimeFactory $timeFactory) {
$this->filterStringParser = $filterStringParser;
$this->mailboxMapper = $mailboxMapper;
$this->imapSearchProvider = $imapSearchProvider;
$this->messageMapper = $messageMapper;
$this->previewEnhancer = $previewEnhancer;
+ $this->timeFactory = $timeFactory;
}
public function findMessage(Account $account,
@@ -101,7 +107,7 @@ class MailSearch implements IMailSearch {
?string $filter,
?int $cursor,
?int $limit): array {
- if ($mailbox->hasLocks()) {
+ if ($mailbox->hasLocks($this->timeFactory->getTime())) {
throw MailboxLockedException::from($mailbox);
}
if (!$mailbox->isCached()) {