remove abuse from deletes worker

This commit is contained in:
shimon 2025-01-08 15:54:31 +02:00
parent 33a8da45bd
commit 18f17ff9fb

View file

@ -7,7 +7,6 @@ use Appwrite\Certificates\Adapter as CertificatesAdapter;
use Appwrite\Extend\Exception; use Appwrite\Extend\Exception;
use Executor\Executor; use Executor\Executor;
use Throwable; use Throwable;
use Utopia\Abuse\Abuse;
use Utopia\Audit\Audit; use Utopia\Audit\Audit;
use Utopia\Cache\Adapter\Filesystem; use Utopia\Cache\Adapter\Filesystem;
use Utopia\Cache\Cache; use Utopia\Cache\Cache;
@ -52,13 +51,12 @@ class Deletes extends Action
->inject('deviceForBuilds') ->inject('deviceForBuilds')
->inject('deviceForCache') ->inject('deviceForCache')
->inject('certificates') ->inject('certificates')
->inject('abuseRetention')
->inject('executionRetention') ->inject('executionRetention')
->inject('auditRetention') ->inject('auditRetention')
->inject('log') ->inject('log')
->callback( ->callback(
fn ($message, $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, int $abuseRetention, string $executionRetention, string $auditRetention, Log $log) => fn ($message, $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log) =>
$this->action($message, $dbForPlatform, $getProjectDB, $timelimit, $deviceForFiles, $deviceForFunctions, $deviceForBuilds, $deviceForCache, $certificates, $abuseRetention, $executionRetention, $auditRetention, $log) $this->action($message, $dbForPlatform, $getProjectDB, $timelimit, $deviceForFiles, $deviceForFunctions, $deviceForBuilds, $deviceForCache, $certificates, $executionRetention, $auditRetention, $log)
); );
} }
@ -66,7 +64,7 @@ class Deletes extends Action
* @throws Exception * @throws Exception
* @throws Throwable * @throws Throwable
*/ */
public function action(Message $message, Database $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, int $abuseRetention, string $executionRetention, string $auditRetention, Log $log): void public function action(Message $message, Database $dbForPlatform, callable $getProjectDB, callable $timelimit, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log): void
{ {
$payload = $message->getPayload() ?? []; $payload = $message->getPayload() ?? [];
@ -125,9 +123,6 @@ class Deletes extends Action
$this->deleteAuditLogs($project, $getProjectDB, $auditRetention); $this->deleteAuditLogs($project, $getProjectDB, $auditRetention);
} }
break; break;
case DELETE_TYPE_ABUSE:
$this->deleteAbuseLogs($project, $timelimit, $abuseRetention);
break;
case DELETE_TYPE_REALTIME: case DELETE_TYPE_REALTIME:
$this->deleteRealtimeUsage($dbForPlatform, $datetime); $this->deleteRealtimeUsage($dbForPlatform, $datetime);
break; break;
@ -700,26 +695,6 @@ class Deletes extends Action
], $dbForPlatform); ], $dbForPlatform);
} }
/**
* @param Database $dbForPlatform
* @param callable $getProjectDB
* @param int $abuseRetention
* @return void
* @throws Exception
*/
private function deleteAbuseLogs(Document $project, callable $timelimit, int $abuseRetention): void
{
$projectId = $project->getId();
$timeLimit = $timelimit("", 0, 1);
$abuse = new Abuse($timeLimit);
try {
$abuse->cleanup($abuseRetention);
} catch (DatabaseException $e) {
Console::error('Failed to delete abuse logs for project ' . $projectId . ': ' . $e->getMessage());
}
}
/** /**
* @param Database $dbForPlatform * @param Database $dbForPlatform
* @param callable $getProjectDB * @param callable $getProjectDB