Skip to content

Commit

Permalink
dateTime bug fix in the deletes worker
Browse files Browse the repository at this point in the history
dateTime small fix
  • Loading branch information
shimonewman committed Aug 31, 2022
1 parent b202302 commit dab8443
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
9 changes: 4 additions & 5 deletions app/controllers/shared/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,16 @@
$signature = md5($data);
$cacheLog = $dbForProject->getDocument('cache', $key);
$accessedAt = $cacheLog->getAttribute('accessedAt', '');
$accessedAt = (new \DateTime($accessedAt))->format('Y/m/d');

$now = DateTime::now();
if ($cacheLog->isEmpty()) {
Authorization::skip(fn () => $dbForProject->createDocument('cache', new Document([
'$id' => $key,
'resource' => $resource,
'accessedAt' => DateTime::now(),
'accessedAt' => $now,
'signature' => $signature,
])));
} elseif ((new \DateTime(DateTime::now()))->format('Y/m/d') > $accessedAt) {
$cacheLog->setAttribute('accessedAt', DateTime::now());
} elseif (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCCESS)) > $accessedAt) {
$cacheLog->setAttribute('accessedAt', $now);
Authorization::skip(fn () => $dbForProject->updateDocument('cache', $cacheLog->getId(), $cacheLog));
}

Expand Down
2 changes: 1 addition & 1 deletion app/workers/deletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected function deleteUsageStats(string $datetime1d, string $datetime30m)
], $dbForProject);

$this->deleteByGroup('stats', [
Query::lessThan('time', [$datetime30m]),
Query::lessThan('time', $datetime30m),
Query::equal('period', ['30m']),
], $dbForProject);
});
Expand Down
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/Appwrite/Event/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class Delete extends Event
protected ?Document $document = null;
protected ?string $resource = null;
protected ?string $datetime = null;
protected ?string $datetime1d = null;
protected ?string $datetime30m = null;
protected ?string $dateTime30m = null;
protected ?string $dateTime1d = null;


public function __construct()
{
Expand Down Expand Up @@ -60,9 +61,9 @@ public function setDatetime(string $datetime): self
* @param string $datetime
* @return self
*/
public function setDatetime1d(string $datetime): self
public function setDateTime1d(string $datetime): self
{
$this->datetime1d = $datetime;
$this->dateTime1d = $datetime;
return $this;
}

Expand All @@ -72,9 +73,9 @@ public function setDatetime1d(string $datetime): self
* @param string $datetime
* @return self
*/
public function setDatetime30m(string $datetime): self
public function setDateTime30m(string $datetime): self
{
$this->datetime30m = $datetime;
$this->dateTime30m = $datetime;
return $this;
}

Expand Down Expand Up @@ -139,8 +140,8 @@ public function trigger(): string|bool
'document' => $this->document,
'resource' => $this->resource,
'datetime' => $this->datetime,
'datetime1d' => $this->datetime1d,
'datetime30m' => $this->datetime30m,
'dateTime1d' => $this->dateTime1d,
'dateTime30m' => $this->dateTime30m,
]);
}
}

0 comments on commit dab8443

Please sign in to comment.