diff --git a/components/HashedStaticCache.php b/components/HashedStaticCache.php index dc2efe442..337d93340 100644 --- a/components/HashedStaticCache.php +++ b/components/HashedStaticCache.php @@ -15,6 +15,8 @@ class HashedStaticCache private bool $isBulky = false; private bool $isSynchronized = false; private bool $skipCache = false; + private bool $noFlush = false; + private bool $forceRebuild = false; private ?int $timeout = null; public function __construct(string $functionName, ?array $dependencies) @@ -46,6 +48,20 @@ public function isSkipCache(): bool return $this->skipCache; } + public function setNoFlush(bool $noFlush): self + { + $this->noFlush = $noFlush; + + return $this; + } + + public function forceRebuild(): self + { + $this->forceRebuild = true; + + return $this; + } + public function setIsBulky(bool $isBulky): self { $this->isBulky = $isBulky; @@ -89,7 +105,7 @@ public function getCached(callable $method): mixed if (!$this->skipCache) { // Hint: don't even try to aquire a lock if a cache item already exists $cached = $this->getCache(); - if ($cached !== false) { + if ($cached !== false && !$this->forceRebuild) { return $cached; } } @@ -99,7 +115,7 @@ public function getCached(callable $method): mixed // Check if the cache item has been generated in the meantime $cached = $this->getCache(); - if ($cached !== false) { + if ($cached !== false && !$this->forceRebuild) { ResourceLock::unlockCache($this); return $cached; } @@ -164,6 +180,10 @@ public function setCache(mixed $data): void public function flushCache(): void { + if ($this->noFlush) { + return; + } + if ($this->isBulky && AntragsgruenApp::getInstance()->viewCacheFilePath) { $directory = self::getDirectory($this->cacheKey); if (file_exists($directory . '/' . $this->cacheKey)) { diff --git a/config/urls.php b/config/urls.php index 5e8ff5712..e04524f0d 100644 --- a/config/urls.php +++ b/config/urls.php @@ -23,6 +23,7 @@ $consultationPaths = 'search|maintenance|notifications|activitylog|collecting|save-agenda-item-ajax|del-agenda-item-ajax|save-agenda-order-ajax'; $consultationPaths .= '|resolutions|motions|todo|todo-count|votings|voting-results|feeds|feedall|feedmotions|feedamendments|feedcomments'; $consultationPaths .= '|speech|admin-speech|admin-votings|proposed-procedure|proposed-procedure-ajax|debugbar-ajax'; +$consultationPaths .= '|rebuild-homepage'; $motionPaths = 'createconfirm|createdone|edit|pdf|pdfamendcollection|pdfembed|odt|plainhtml|viewimage|viewpdf|embeddedpdf|embedded-amendments-pdf'; $motionPaths .= '|admin-speech|withdraw|view-changes|view-changes-odt'; $motionPaths .= '|save-proposal-status|edit-proposed-change|del-proposal-comment|save-editorial'; diff --git a/controllers/ConsultationController.php b/controllers/ConsultationController.php index c16f1d4f7..5beaae0ef 100644 --- a/controllers/ConsultationController.php +++ b/controllers/ConsultationController.php @@ -13,7 +13,7 @@ RedirectResponse, ResponseInterface, RestApiResponse}; -use app\components\{DateTools, RSSExporter, Tools, UrlHelper}; +use app\components\{DateTools, HashedStaticCache, RSSExporter, Tools, UrlHelper}; use app\models\db\{Amendment, AmendmentComment, IComment, @@ -311,6 +311,28 @@ public function actionIndex(): ResponseInterface $this->consultation->preloadAllMotionData(Consultation::PRELOAD_ONLY_AMENDMENTS); } + return $this->renderHomePage($cache); + } + + public function actionRebuildHomepage(): ResponseInterface + { + $user = User::getCurrentUser(); + if ($user) { + return new HtmlResponse('Diesen Link bitte nicht eingeloggt öffnen, z.B. in einem privaten Fenster'); + } + + $cache = LayoutHelper::getHomePageCache($this->consultation); + $cache->forceRebuild(); + + if ($cache->isSkipCache() || !$cache->cacheIsFilled()) { + $this->consultation->preloadAllMotionData(Consultation::PRELOAD_ONLY_AMENDMENTS); + } + + return $this->renderHomePage($cache); + } + + private function renderHomePage(HashedStaticCache $cache): HtmlResponse + { $this->layout = 'column2'; $this->consultationSidebar($this->consultation); diff --git a/views/consultation/LayoutHelper.php b/views/consultation/LayoutHelper.php index fdac7a163..a3f893913 100644 --- a/views/consultation/LayoutHelper.php +++ b/views/consultation/LayoutHelper.php @@ -22,6 +22,7 @@ private static function getHomePageCacheForType(Consultation $consultation, stri if (AntragsgruenApp::getInstance()->viewCacheFilePath) { $cache->setIsSynchronized(true); $cache->setIsBulky(true); + $cache->setNoFlush(true); } else { $cache->setSkipCache(true); }