mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
patch: deletes worker refactoring
This commit is contained in:
@@ -253,7 +253,7 @@ App::delete('/v1/database/collections/:collectionId')
|
||||
|
||||
$deletes
|
||||
->setParam('document', $collection)
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
->setParam('type', DELETE_TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
$events
|
||||
|
||||
@@ -366,7 +366,7 @@ App::delete('/v1/functions/:functionId')
|
||||
|
||||
$deletes
|
||||
->setParam('document', $function->getArrayCopy())
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
->setParam('type', DELETE_TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
$response->noContent();
|
||||
|
||||
@@ -431,7 +431,7 @@ App::delete('/v1/projects/:projectId')
|
||||
|
||||
$deletes
|
||||
->setParam('document', $project->getArrayCopy())
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
->setParam('type', DELETE_TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
foreach (['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms)
|
||||
|
||||
@@ -517,7 +517,7 @@ App::delete('/v1/users/:userId')
|
||||
|
||||
$deletes
|
||||
->setParam('document', $user)
|
||||
->setParam('type', DeletesV1::TYPE_DOCUMENT)
|
||||
->setParam('type', DELETE_TYPE_DOCUMENT)
|
||||
;
|
||||
|
||||
$events
|
||||
|
||||
+5
-1
@@ -52,7 +52,11 @@ const APP_SOCIAL_INSTAGRAM = 'https://www.instagram.com/appwrite.io';
|
||||
const APP_SOCIAL_GITHUB = 'https://github.com/appwrite';
|
||||
const APP_SOCIAL_DISCORD = 'https://appwrite.io/discord';
|
||||
const APP_SOCIAL_DEV = 'https://dev.to/appwrite';
|
||||
const APP_SOCIAL_STACKSHARE = 'https://stackshare.io/appwrite';
|
||||
const APP_SOCIAL_STACKSHARE = 'https://stackshare.io/appwrite';
|
||||
// Deletion Types
|
||||
const DELETE_TYPE_DOCUMENT = 'document';
|
||||
const DELETE_TYPE_AUDIT = 'audit';
|
||||
const DELETE_TYPE_ABUSE = 'abuse';
|
||||
|
||||
$register = new Registry();
|
||||
|
||||
|
||||
+12
-12
@@ -30,7 +30,7 @@ function getConsoleDB() {
|
||||
function notifyDeleteExecutionLogs(array $projectIds)
|
||||
{
|
||||
Resque::enqueue(DELETE_QUEUE_NAME, DELETE_CLASS_NAME, [
|
||||
'type' => DeletesV1::TYPE_DOCUMENT,
|
||||
'type' => DELETE_TYPE_DOCUMENT,
|
||||
'document' => new Document([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||
'projectIds' => $projectIds
|
||||
@@ -38,24 +38,24 @@ function notifyDeleteExecutionLogs(array $projectIds)
|
||||
]);
|
||||
}
|
||||
|
||||
function notifyDeleteAbuseLogs(array $projectIds, int $timestamp)
|
||||
function notifyDeleteAbuseLogs(array $projectIds, int $interval)
|
||||
{
|
||||
Resque::enqueue(DELETE_QUEUE_NAME, DELETE_CLASS_NAME, [
|
||||
'type' => DeletesV1::TYPE_ABUSE,
|
||||
'type' => DELETE_TYPE_ABUSE,
|
||||
'document' => new Document([
|
||||
'projectIds' => $projectIds,
|
||||
'timestamp' => $timestamp,
|
||||
'timestamp' => time() - $interval,
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
function notifyDeleteAuditLogs(array $projectIds, int $timestamp)
|
||||
function notifyDeleteAuditLogs(array $projectIds, int $interval)
|
||||
{
|
||||
Resque::enqueue(DELETE_QUEUE_NAME, DELETE_CLASS_NAME, [
|
||||
'type' => DeletesV1::TYPE_AUDIT,
|
||||
'type' => DELETE_TYPE_AUDIT,
|
||||
'document' => new Document([
|
||||
'projectIds' => $projectIds,
|
||||
'timestamp' => $timestamp
|
||||
'timestamp' => time() - $interval
|
||||
])
|
||||
]);
|
||||
}
|
||||
@@ -67,11 +67,11 @@ $cli
|
||||
// # of days in seconds (1 day = 86400s)
|
||||
$interval = App::getEnv('_APP_MAINTENANCE_INTERVAL', '') + 0;
|
||||
//Convert Seconds to microseconds
|
||||
$interval = $interval * 1000000;
|
||||
$intervalMicroseconds = $interval * 1000000;
|
||||
|
||||
$consoleDB = getConsoleDB();
|
||||
|
||||
Console::loop(function() use ($consoleDB){
|
||||
Console::loop(function() use ($consoleDB, $interval){
|
||||
|
||||
Authorization::disable();
|
||||
$projects = $consoleDB->getCollection([
|
||||
@@ -86,9 +86,9 @@ $cli
|
||||
}, $projects);
|
||||
|
||||
notifyDeleteExecutionLogs($projectIds);
|
||||
notifyDeleteAbuseLogs($projectIds);
|
||||
notifyDeleteAuditLogs($projectIds);
|
||||
notifyDeleteAbuseLogs($projectIds, $interval);
|
||||
notifyDeleteAuditLogs($projectIds, $interval);
|
||||
|
||||
}, $interval);
|
||||
}, $intervalMicroseconds);
|
||||
|
||||
});
|
||||
+17
-11
@@ -20,11 +20,6 @@ use Utopia\Audit\Adapters\MySQL as AuditAdapter;
|
||||
class DeletesV1
|
||||
{
|
||||
|
||||
// Deletion Types
|
||||
const TYPE_DOCUMENT = 'document';
|
||||
const TYPE_AUDIT = 'audit';
|
||||
const TYPE_ABUSE = 'abuse';
|
||||
|
||||
public $args = [];
|
||||
|
||||
protected $consoleDB = null;
|
||||
@@ -38,10 +33,11 @@ class DeletesV1
|
||||
$document = $this->args['document'];
|
||||
$document = new Document($document);
|
||||
$projectId = $this->args['projectId'];
|
||||
|
||||
$type = $this->args['type'];
|
||||
|
||||
switch (strval($type)) {
|
||||
case DeletesV1::TYPE_DOCUMENT:
|
||||
case DELETE_TYPE_DOCUMENT:
|
||||
switch (strval($document->getCollection())) {
|
||||
case Database::SYSTEM_COLLECTION_PROJECTS:
|
||||
$this->deleteProject($document);
|
||||
@@ -63,11 +59,11 @@ class DeletesV1
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DeletesV1::TYPE_AUDIT:
|
||||
case DELETE_TYPE_AUDIT:
|
||||
$this->deleteAuditLogs($document);
|
||||
break;
|
||||
|
||||
case DeletesV1::TYPE_ABUSE:
|
||||
case DELETE_TYPE_ABUSE:
|
||||
$this->deleteAbuseLogs($document);
|
||||
break;
|
||||
}
|
||||
@@ -137,29 +133,39 @@ class DeletesV1
|
||||
{
|
||||
global $register;
|
||||
$projectIds = $document->getAttribute('projectIds', []);
|
||||
$timestamp = $document->getAttribute('timestamp', 0);
|
||||
|
||||
if($timestamp == 0) {
|
||||
throw new Exception('Failed to delete abuse logs. No timestamp provided');
|
||||
}
|
||||
|
||||
foreach ($projectIds as $projectId) {
|
||||
$adapter = new AuditAdapter($register->get('db'));
|
||||
$adapter->setNamespace('app_'.$projectId);
|
||||
$audit = new Audit($adapter);
|
||||
$status = $audit->cleanup();
|
||||
$status = $audit->cleanup($timestamp);
|
||||
if (!$status) {
|
||||
throw new Exception('Failed to delete Audit logs for project'.$projectId, 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function deleteAuditLogs($document)
|
||||
{
|
||||
global $register;
|
||||
$projectIds = $document->getAttribute('projectIds', []);
|
||||
$timestamp = $document->getAttribute('time', 0);
|
||||
$timestamp = $document->getAttribute('timestamp', 0);
|
||||
|
||||
if($timestamp == 0) {
|
||||
throw new Exception('Failed to delete audit logs. No timestamp provided');
|
||||
}
|
||||
|
||||
foreach ($projectIds as $projectId) {
|
||||
$adapter = new AuditAdapter($register->get('db'));
|
||||
$adapter->setNamespace('app_'.$projectId);
|
||||
$audit = new Audit($adapter);
|
||||
$status = $audit->cleanup();
|
||||
$status = $audit->cleanup($timestamp);
|
||||
if (!$status) {
|
||||
throw new Exception('Failed to delete Audit logs for project'.$projectId, 500);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user