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

[stable29] new daily maintenance to delete old federated events #1776

Merged
merged 3 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
90 changes: 60 additions & 30 deletions .github/workflows/phpunit-oci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: PHPUnit OCI

on:
pull_request:
paths:
- '.github/workflows/**'
- 'appinfo/**'
- 'lib/**'
- 'templates/**'
- 'tests/**'
- 'vendor/**'
- 'vendor-bin/**'
- '.php-cs-fixer.dist.php'
- 'composer.json'
- 'composer.lock'

push:
branches:
- main
- master
- stable*
on: pull_request

permissions:
contents: read
Expand All @@ -33,13 +18,58 @@ concurrency:
cancel-in-progress: true

jobs:
matrix:
runs-on: ubuntu-latest-low
outputs:
php-version: ${{ steps.versions.outputs.php-available-list }}
server-max: ${{ steps.versions.outputs.branches-max-list }}
steps:
- name: Checkout app
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Get version matrix
id: versions
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1

changes:
runs-on: ubuntu-latest-low
permissions:
contents: read
pull-requests: read

outputs:
src: ${{ steps.changes.outputs.src }}

steps:
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes
continue-on-error: true
with:
filters: |
src:
- '.github/workflows/**'
- 'appinfo/**'
- 'lib/**'
- 'templates/**'
- 'tests/**'
- 'vendor/**'
- 'vendor-bin/**'
- '.php-cs-fixer.dist.php'
- 'composer.json'
- 'composer.lock'

phpunit-oci:
runs-on: ubuntu-latest

needs: [changes, matrix]
if: needs.changes.outputs.src != 'false'

strategy:
matrix:
php-versions: ['8.1']
server-versions: ['stable29']
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}

name: OCI PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}

services:
oracle:
Expand Down Expand Up @@ -69,19 +99,19 @@ jobs:
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV

- name: Checkout server
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
submodules: true
repository: nextcloud/server
ref: ${{ matrix.server-versions }}

- name: Checkout app
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
path: apps/${{ env.APP_NAME }}

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # v2
uses: shivammathur/setup-php@2e947f1f6932d141d076ca441d0e1e881775e95b # v2.31.0
with:
php-version: ${{ matrix.php-versions }}
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
Expand All @@ -93,7 +123,7 @@ jobs:

- name: Check composer file existence
id: check_composer
uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
with:
files: apps/${{ env.APP_NAME }}/composer.json

Expand All @@ -116,7 +146,7 @@ jobs:
continue-on-error: true
working-directory: apps/${{ env.APP_NAME }}
run: |
composer run --list | grep "^ test:unit " | wc -l | grep 1
composer run --list | grep '^ test:unit ' | wc -l | grep 1

- name: PHPUnit
# Only run if phpunit config file exists
Expand All @@ -129,7 +159,7 @@ jobs:
continue-on-error: true
working-directory: apps/${{ env.APP_NAME }}
run: |
composer run --list | grep "^ test:integration " | wc -l | grep 1
composer run --list | grep '^ test:integration ' | wc -l | grep 1

- name: Run Nextcloud
# Only run if phpunit integration config file exists
Expand Down Expand Up @@ -157,13 +187,13 @@ jobs:
summary:
permissions:
contents: none
runs-on: ubuntu-latest
needs: phpunit-oci
runs-on: ubuntu-latest-low
needs: [changes, phpunit-oci]

if: always()

name: phpunit-oci-summary

steps:
- name: Summary status
run: if ${{ needs.phpunit-oci.result != 'success' }}; then exit 1; fi
run: if ${{ needs.changes.outputs.src != 'false' && needs.phpunit-oci.result != 'success' }}; then exit 1; fi
18 changes: 18 additions & 0 deletions lib/Db/EventWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,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 @@ -35,6 +35,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 @@ -49,6 +50,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 @@ -60,7 +62,6 @@ class MaintenanceService {
use TNCLogger;

public const TIMEOUT = 18000;

public static $DELAY =
[
1 => 60, // every minute
Expand All @@ -70,94 +71,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 @@ -287,6 +219,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 @@ -519,8 +458,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