Fix excessive increase of cachebuster value

Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
Christopher Ng 2022-10-08 00:52:09 +00:00
parent 8d05e180bc
commit 46ee620150
3 changed files with 12 additions and 3 deletions

View file

@ -34,6 +34,7 @@ use OCA\Theming\AppInfo\Application;
use OCA\Theming\ITheme;
use OCA\Theming\Service\BackgroundService;
use OCA\Theming\Service\ThemesService;
use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
@ -53,6 +54,7 @@ class UserThemeController extends OCSController {
private IConfig $config;
private IUserSession $userSession;
private ThemesService $themesService;
private ThemingDefaults $themingDefaults;
private BackgroundService $backgroundService;
/**
@ -63,11 +65,13 @@ class UserThemeController extends OCSController {
IConfig $config,
IUserSession $userSession,
ThemesService $themesService,
ThemingDefaults $themingDefaults,
BackgroundService $backgroundService) {
parent::__construct($appName, $request);
$this->config = $config;
$this->userSession = $userSession;
$this->themesService = $themesService;
$this->themingDefaults = $themingDefaults;
$this->backgroundService = $backgroundService;
$this->userId = $userSession->getUser()->getUID();
}
@ -177,6 +181,8 @@ class UserThemeController extends OCSController {
}
$currentVersion++;
$this->config->setUserValue($this->userId, Application::APP_ID, 'backgroundVersion', (string)$currentVersion);
// FIXME replace with user-specific cachebuster increase https://github.com/nextcloud/server/issues/34472
$this->themingDefaults->increaseCacheBuster();
return new JSONResponse([
'type' => $type,
'value' => $value,

View file

@ -224,10 +224,8 @@ class ThemingDefaults extends \OC_Defaults {
if ($color === '' && !empty($user)) {
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
if ($themingBackground === 'default') {
$this->increaseCacheBuster();
return BackgroundService::DEFAULT_COLOR;
} else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
$this->increaseCacheBuster();
return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
}
}
@ -411,7 +409,7 @@ class ThemingDefaults extends \OC_Defaults {
/**
* Increases the cache buster key
*/
private function increaseCacheBuster(): void {
public function increaseCacheBuster(): void {
$cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0');
$this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1));
$this->cacheFactory->createDistributed('theming-')->clear();

View file

@ -33,6 +33,7 @@ use OCA\Theming\Themes\DyslexiaFont;
use OCA\Theming\Themes\HighContrastTheme;
use OCA\Theming\Service\ThemesService;
use OCA\Theming\Themes\LightTheme;
use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\IConfig;
@ -54,6 +55,8 @@ class UserThemeControllerTest extends TestCase {
private $userSession;
/** @var ThemeService|MockObject */
private $themesService;
/** @var ThemingDefaults */
private $themingDefaults;
/** @var BackgroundService|MockObject */
private $backgroundService;
@ -66,6 +69,7 @@ class UserThemeControllerTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->themesService = $this->createMock(ThemesService::class);
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
$this->backgroundService = $this->createMock(BackgroundService::class);
$this->themes = [
@ -91,6 +95,7 @@ class UserThemeControllerTest extends TestCase {
$this->config,
$this->userSession,
$this->themesService,
$this->themingDefaults,
$this->backgroundService,
);