Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] new daily maintenance to delete old federated events #1777

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
115 changes: 26 additions & 89 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 = null;

/** @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 Expand Up @@ -499,8 +438,6 @@ private function canRunLevel(int $level, SimpleDataStore $last): bool {
* @param string $message
*/
private function output(string $message): void {
if (!is_null($this->output)) {
$this->output->writeln('- ' . $message);
}
$this->output?->writeln('- ' . $message);
}
}
Loading