Skip to content

Commit

Permalink
refresh display name
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed May 4, 2023
1 parent 65b0b4b commit f6e9e72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
6 changes: 4 additions & 2 deletions lib/Command/CirclesMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ protected function configure() {
->addOption(
'uninstall', '', InputOption::VALUE_NONE,
'Uninstall the apps and everything related to the app from the database'
);
)
->addOption('force-refresh', '', InputOption::VALUE_NONE, 'enforce some refresh');
}


Expand Down Expand Up @@ -154,9 +155,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->outputService->setOccOutput($output);
$this->maintenanceService->setOccOutput($output);

for ($i = 1; $i <= $level; $i++) {
try {
$this->maintenanceService->runMaintenance($i);
$this->maintenanceService->runMaintenance($i, $input->getOption('force-refresh'));
} catch (MaintenanceException $e) {
}
}
Expand Down
38 changes: 19 additions & 19 deletions lib/Service/MaintenanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,27 @@ public function setOccOutput(OutputInterface $output): void {
*
* @throws MaintenanceException
*/
public function runMaintenance(int $level): void {
public function runMaintenance(int $level, bool $forceRefresh = false): void {
$this->federatedUserService->bypassCurrentUserCondition(true);

$this->lockMaintenanceRun();
$this->debug('running maintenance (' . $level . ')');

switch ($level) {
case 1:
$this->runMaintenance1();
$this->runMaintenance1($forceRefresh);
break;
case 2:
$this->runMaintenance2();
$this->runMaintenance2($forceRefresh);
break;
case 3:
$this->runMaintenance3();
$this->runMaintenance3($forceRefresh);
break;
case 4:
$this->runMaintenance4();
$this->runMaintenance4($forceRefresh);
break;
case 5:
$this->runMaintenance5();
$this->runMaintenance5($forceRefresh);
break;
}

Expand All @@ -217,7 +217,7 @@ private function lockMaintenanceRun(): void {
/**
* every minute
*/
private function runMaintenance1(): void {
private function runMaintenance1(bool $forceRefresh = false): void {
try {
$this->output('Remove circles with no owner');
$this->removeCirclesWithNoOwner();
Expand All @@ -229,7 +229,7 @@ private function runMaintenance1(): void {
/**
* every 10 minutes
*/
private function runMaintenance2(): void {
private function runMaintenance2(bool $forceRefresh = false): void {
try {
$this->output('Remove members with no circles');
$this->removeMembersWithNoCircles();
Expand All @@ -247,7 +247,7 @@ private function runMaintenance2(): void {
/**
* every hour
*/
private function runMaintenance3(): void {
private function runMaintenance3(bool $forceRefresh = false): void {
try {
$this->output('Retry failed FederatedEvents (hourly)');
$this->eventWrapperService->retry(EventWrapperService::RETRY_HOURLY);
Expand All @@ -259,7 +259,7 @@ private function runMaintenance3(): void {
/**
* every day
*/
private function runMaintenance4(): void {
private function runMaintenance4(bool $forceRefresh = false): void {
try {
$this->output('Retry failed FederatedEvents (daily)');
$this->eventWrapperService->retry(EventWrapperService::RETRY_DAILY);
Expand All @@ -285,18 +285,18 @@ private function runMaintenance4(): void {
/**
* every week
*/
private function runMaintenance5(): void {
private function runMaintenance5(bool $forceRefresh = false): void {
try {
$this->output('Update memberships');
$this->updateAllMemberships();
} catch (Exception $e) {
}

// try {
// $this->output('refresh displayNames older than 7d');
// $this->refreshDisplayName();
// } catch (Exception $e) {
// }
try {
$this->output('refresh members\' display name');
$this->refreshDisplayName($forceRefresh);
} catch (Exception $e) {
}

try {
// Can be removed in NC27.
Expand Down Expand Up @@ -403,7 +403,7 @@ private function updateAllMemberships(): void {
* @throws RequestBuilderException
* @throws InitiatorNotFoundException
*/
private function refreshDisplayName(): void {
private function refreshDisplayName(bool $forceRefresh = false): void {
$circleFilter = new Circle();
$circleFilter->setConfig(Circle::CFG_SINGLE);

Expand All @@ -416,8 +416,8 @@ private function refreshDisplayName(): void {

foreach ($circles as $circle) {
$owner = $circle->getOwner();
if ($owner->getDisplayUpdate() > (time() - 604800)) {
continue;
if (!$forceRefresh && $owner->getDisplayUpdate() > (time() - 691200)) {
continue; // ignore update done in the last 8 days.
}

if ($owner->getUserType() === Member::TYPE_USER) {
Expand Down

0 comments on commit f6e9e72

Please sign in to comment.