Skip to content

Commit

Permalink
fixup! fixup! Add check for timestamp to hasLocks
Browse files Browse the repository at this point in the history
  • Loading branch information
miaulalala committed Mar 24, 2021
1 parent b9041f6 commit b3fc064
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 9 additions & 3 deletions lib/Db/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -120,13 +126,13 @@ public function isCached(): bool {
}

public function hasLocks(int $now): bool {
if ($this->getSyncNewLock() !== null || $this->getSyncNewLock() > ($now - MailboxMapper::LOCK)) {
if ($this->getSyncNewLock() !== null || $this->getSyncNewLock() > ($now - self::LOCK_TIMEOUT)) {
return true;
}
if ($this->getSyncChangedLock() !== null || $this->getSyncChangedLock() > ($now - MailboxMapper::LOCK)) {
if ($this->getSyncChangedLock() !== null || $this->getSyncChangedLock() > ($now - self::LOCK_TIMEOUT)) {
return true;
}
if ($this->getSyncVanishedLock() !== null || $this->getSyncVanishedLock() > ($now - MailboxMapper::LOCK)) {
if ($this->getSyncVanishedLock() !== null || $this->getSyncVanishedLock() > ($now - self::LOCK_TIMEOUT)) {
return true;
}
return false;
Expand Down
8 changes: 1 addition & 7 deletions lib/Db/MailboxMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@

class MailboxMapper extends QBMapper {

/**
* @var int
* Lock timeout for sync (5 minutes)
*/
public const LOCK = 300;

/** @var ITimeFactory */
private $timeFactory;

Expand Down Expand Up @@ -149,7 +143,7 @@ private function lockForSync(Mailbox $mailbox, string $attr, ?int $lock): int {
$now = $this->timeFactory->getTime();

if ($lock !== null
&& $lock > ($now - self::LOCK)) {
&& $lock > ($now - Mailbox::LOCK_TIMEOUT)) {
// Another process is syncing
throw MailboxLockedException::from($mailbox);
}
Expand Down

0 comments on commit b3fc064

Please sign in to comment.