Skip to content

Commit bf15b43

Browse files
committed
perf(DiagnosticService): Don't store data in AppConfig
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 396f12b commit bf15b43

File tree

2 files changed

+34
-68
lines changed

2 files changed

+34
-68
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\ContextChat\Migration;
11+
12+
use Closure;
13+
use OCP\AppFramework\Services\IAppConfig;
14+
use OCP\Migration\IOutput;
15+
use OCP\Migration\SimpleMigrationStep;
16+
17+
class Version004002001Date20250410110041 extends SimpleMigrationStep {
18+
19+
public function __construct(
20+
private IAppConfig $appConfig,
21+
) {
22+
}
23+
24+
/**
25+
* @param IOutput $output
26+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
27+
* @param array $options
28+
*
29+
* @return void
30+
*/
31+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
32+
$this->appConfig->deleteAppValue('background_jobs_diagnostics');
33+
}
34+
}

lib/Service/DiagnosticService.php

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace OCA\ContextChat\Service;
99

1010
use OCP\AppFramework\Services\IAppConfig;
11-
use OCP\Exceptions\AppConfigTypeConflictException;
1211
use OCP\Util;
1312
use Psr\Log\LoggerInterface;
1413

@@ -20,42 +19,13 @@ public function __construct(
2019
) {
2120
}
2221

23-
/**
24-
* @return array
25-
* @throws AppConfigTypeConflictException
26-
*/
27-
public function getBackgroundJobDiagnostics(): array {
28-
return $this->appConfig->getAppValueArray('background_jobs_diagnostics', [], true);
29-
}
30-
31-
/**
32-
* @param array $value
33-
* @return void
34-
* @throws AppConfigTypeConflictException
35-
* @throws \JsonException
36-
*/
37-
private function setBackgroundJobDiagnostics(array $value): void {
38-
$this->appConfig->setAppValueArray('background_jobs_diagnostics', $value, true);
39-
}
40-
4122
/**
4223
* @param string $class
4324
* @param int $id
4425
* @return void
4526
*/
4627
public function sendJobTrigger(string $class, int $id): void {
4728
$this->logger->info('CONTEXT_CHAT_DIAGNOSTICS: ' . $class . ' ' . $id . ' triggered');
48-
$key = $class . '-' . $id;
49-
try {
50-
$diagnostics = $this->getBackgroundJobDiagnostics();
51-
if (!isset($diagnostics[$key])) {
52-
$diagnostics[$key] = [];
53-
}
54-
$diagnostics[$key] = array_merge(['last_triggered' => time()], $diagnostics[$key]);
55-
$this->setBackgroundJobDiagnostics($diagnostics);
56-
} catch (\OCP\Exceptions\AppConfigTypeConflictException|\JsonException $e) {
57-
$this->logger->warning('Error during context chat diagnostic jobStart', ['exception' => $e]);
58-
}
5929
}
6030

6131
/**
@@ -65,22 +35,6 @@ public function sendJobTrigger(string $class, int $id): void {
6535
*/
6636
public function sendJobStart(string $class, int $id): void {
6737
$this->logger->info('CONTEXT_CHAT_DIAGNOSTICS: ' . $class . ' ' . $id . ' started');
68-
$key = $class . '-' . $id;
69-
try {
70-
$diagnostics = $this->getBackgroundJobDiagnostics();
71-
if (!isset($diagnostics[$key])) {
72-
$diagnostics[$key] = [];
73-
}
74-
$diagnostics[$key] = array_merge(['last_started' => time()], $diagnostics[$key]);
75-
if (isset($diagnostics[$key]['started_count'])) {
76-
$diagnostics[$key]['started_count']++;
77-
} else {
78-
$diagnostics[$key]['started_count'] = 1;
79-
}
80-
$this->setBackgroundJobDiagnostics($diagnostics);
81-
} catch (\OCP\Exceptions\AppConfigTypeConflictException|\JsonException $e) {
82-
$this->logger->warning('Error during context chat diagnostic jobStart', ['exception' => $e]);
83-
}
8438
}
8539

8640
/**
@@ -90,17 +44,6 @@ public function sendJobStart(string $class, int $id): void {
9044
*/
9145
public function sendJobEnd(string $class, int $id): void {
9246
$this->logger->info('CONTEXT_CHAT_DIAGNOSTICS: ' . $class . ' ' . $id . ' ended');
93-
$key = $class . '-' . $id;
94-
try {
95-
$diagnostics = $this->getBackgroundJobDiagnostics();
96-
if (!isset($diagnostics[$key])) {
97-
$diagnostics[$key] = [];
98-
}
99-
$diagnostics[$key] = array_merge(['last_ended' => time()], $diagnostics[$key]);
100-
$this->setBackgroundJobDiagnostics($diagnostics);
101-
} catch (\OCP\Exceptions\AppConfigTypeConflictException|\JsonException $e) {
102-
$this->logger->warning('Error during context chat diagnostic jobStart', ['exception' => $e]);
103-
}
10447
}
10548

10649
/**
@@ -110,17 +53,6 @@ public function sendJobEnd(string $class, int $id): void {
11053
*/
11154
public function sendHeartbeat(string $class, int $id): void {
11255
$this->logger->info('CONTEXT_CHAT_DIAGNOSTICS: ' . $class . ' ' . $id . ' running');
113-
$key = $class . '-' . $id;
114-
try {
115-
$diagnostics = $this->getBackgroundJobDiagnostics();
116-
if (!isset($diagnostics[$key])) {
117-
$diagnostics[$key] = [];
118-
}
119-
$diagnostics[$key] = array_merge(['last_seen' => time()], $diagnostics[$key]);
120-
$this->setBackgroundJobDiagnostics($diagnostics);
121-
} catch (\OCP\Exceptions\AppConfigTypeConflictException|\JsonException $e) {
122-
$this->logger->warning('Error during context chat diagnostic heartbeat', ['exception' => $e]);
123-
}
12456
}
12557

12658
/**

0 commit comments

Comments
 (0)