Skip to content

Commit

Permalink
new daily maintenance to delete old federated events
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Nov 26, 2024
1 parent c810e8c commit 2d4da8f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 86 deletions.
18 changes: 18 additions & 0 deletions lib/Db/EventWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,22 @@ public function getByToken(string $token): array {

return $this->getItemsFromRequest($qb);
}

/**
* delete completed entries older than a month
*
* @param bool $allOldEntries delete also not-completed entries
*/
public function deleteOldEntries(bool $allOldEntries = false): void {
$qb = $this->getEventWrapperDeleteSql();
$qb->where(
$qb->exprLimitInt('status', EventWrapper::STATUS_OVER),
$qb->exprLt('creation', time() - 30 * 86400)
);
if (!$allOldEntries) {
$qb->andWhere($qb->exprLimitInt('status', EventWrapper::STATUS_OVER));
}

$qb->executeStatement();
}
}
111 changes: 25 additions & 86 deletions lib/Service/MaintenanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OC\User\NoUserException;
use OCA\Circles\Db\AccountsRequest;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Db\EventWrapperRequest;
use OCA\Circles\Db\MemberRequest;
use OCA\Circles\Db\ShareWrapperRequest;
use OCA\Circles\Exceptions\InitiatorNotFoundException;
Expand All @@ -29,6 +30,7 @@
use OCA\Circles\Tools\Traits\TNCLogger;
use OCP\IGroupManager;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -40,7 +42,6 @@ class MaintenanceService {
use TNCLogger;

public const TIMEOUT = 18000;

public static $DELAY =
[
1 => 60, // every minute
Expand All @@ -50,94 +51,25 @@ class MaintenanceService {
5 => 432000 // evey week
];

private OutputInterface $output;

/** @var IUserManager */
private $userManager;

/** @var IGroupManager */
private $groupManager;

/** @var AccountsRequest */
private $accountRequest;

/** @var CircleRequest */
private $circleRequest;

/** @var MemberRequest */
private $memberRequest;

/** @var ShareWrapperRequest */
private $shareWrapperRequest;

/** @var SyncService */
private $syncService;

/** @var FederatedUserService */
private $federatedUserService;

private ShareWrapperService $shareWrapperService;

/** @var MembershipService */
private $membershipService;

/** @var EventWrapperService */
private $eventWrapperService;

/** @var CircleService */
private $circleService;

/** @var ConfigService */
private $configService;


/** @var OutputInterface */
private $output;


/**
* MaintenanceService constructor.
*
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param CircleRequest $circleRequest
* @param MemberRequest $memberRequest
* @param ShareWrapperRequest $shareWrapperRequest
* @param SyncService $syncService
* @param FederatedUserService $federatedUserService
* @param ShareWrapperService $shareWrapperService
* @param MembershipService $membershipService
* @param EventWrapperService $eventWrapperService
* @param CircleService $circleService
* @param ConfigService $configService
*/
public function __construct(
IUserManager $userManager,
IGroupManager $groupManager,
CircleRequest $circleRequest,
AccountsRequest $accountRequest,
MemberRequest $memberRequest,
ShareWrapperRequest $shareWrapperRequest,
SyncService $syncService,
FederatedUserService $federatedUserService,
ShareWrapperService $shareWrapperService,
MembershipService $membershipService,
EventWrapperService $eventWrapperService,
CircleService $circleService,
ConfigService $configService,
private IUserManager $userManager,
private IGroupManager $groupManager,
private CircleRequest $circleRequest,
private AccountsRequest $accountRequest,
private MemberRequest $memberRequest,
private ShareWrapperRequest $shareWrapperRequest,
private EventWrapperRequest $eventWrapperRequest,
private SyncService $syncService,
private FederatedUserService $federatedUserService,
private ShareWrapperService $shareWrapperService,
private MembershipService $membershipService,
private EventWrapperService $eventWrapperService,
private CircleService $circleService,
private ConfigService $configService,
private LoggerInterface $logger,
) {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->circleRequest = $circleRequest;
$this->accountRequest = $accountRequest;
$this->memberRequest = $memberRequest;
$this->shareWrapperRequest = $shareWrapperRequest;
$this->syncService = $syncService;
$this->federatedUserService = $federatedUserService;
$this->shareWrapperService = $shareWrapperService;
$this->eventWrapperService = $eventWrapperService;
$this->membershipService = $membershipService;
$this->circleService = $circleService;
$this->configService = $configService;
}


Expand Down Expand Up @@ -267,6 +199,13 @@ private function runMaintenance4(bool $forceRefresh = false): void {
$this->syncService->sync();
} catch (Exception $e) {
}

try {
$this->output('Delete old and terminated FederatedEvents');
$this->eventWrapperRequest->deleteOldEntries(false);
} catch (Exception $e) {
$this->logger->warning('issue while deleting old events', ['exception' => $e]);
}
}

/**
Expand Down

0 comments on commit 2d4da8f

Please sign in to comment.