Skip to content
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ KEY_VAULT_SOURCE=ENVIRONMENT
KEY_VAULT_JSON="{}"
TRACK_SCREEN_INFO=false
TRACK_SCREEN_INFO_UPDATE_INTERVAL_SECONDS=300
RELATIONS_CHECKSUM_ENABLED=true
###< App ###

###> itk-dev/openid-connect-bundle ###
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file.
- Moved list components (search and checkboxes) around.
- Aligned environment variable names.
- Aligned with v. 2.6.0.
- Added relations checksum feature flag.

### NB! Prior to 3.x the project was split into separate repositories

Expand Down
3 changes: 3 additions & 0 deletions assets/client/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ function App({ preview, previewId }) {

ClientConfigLoader.loadConfig().then((config) => {
setDebug(config.debug ?? false);

const relationChecksumEnabled = config.relationsChecksumEnabled;
logger.info(`Relation checksum enabled: ${relationChecksumEnabled}`);
});

releaseService.checkForNewRelease().finally(() => {
Expand Down
28 changes: 21 additions & 7 deletions assets/client/data-sync/pull-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import isPublished from "../util/isPublished";
import logger from "../logger/logger";
import ApiHelper from "./api-helper";
import { cloneDeep } from "lodash";
import ClientConfigLoader from "../util/client-config-loader.js";

/**
* PullStrategy.
Expand Down Expand Up @@ -195,6 +196,9 @@ class PullStrategy {
return;
}

const config = await ClientConfigLoader.loadConfig();
const relationChecksumEnabled = config.relationsChecksumEnabled;

if (screen === null) {
logger.warn(`Screen (${screenPath}) not loaded`);
return;
Expand All @@ -209,14 +213,15 @@ class PullStrategy {
this.lastestScreenData?.relationsChecksum ?? null;

if (
relationChecksumEnabled === false ||
oldScreenChecksums === null ||
oldScreenChecksums?.campaigns !== newScreenChecksums?.campaigns ||
oldScreenChecksums?.inScreenGroups !== newScreenChecksums?.inScreenGroups
) {
logger.info(`Campaigns or screen groups modified.`);
logger.info(`Fetching campaigns.`);
newScreen.campaignsData = await this.getCampaignsData(newScreen);
} else {
logger.info(`Campaigns or screen groups not modified.`);
logger.info(`Campaigns data loaded from cache.`);
newScreen.campaignsData = this.lastestScreenData.campaignsData;
}

Expand Down Expand Up @@ -262,29 +267,31 @@ class PullStrategy {

// Get layout: Defines layout and regions.
if (
relationChecksumEnabled === false ||
this.lastestScreenData?.hasActiveCampaign ||
oldScreenChecksums === null ||
oldScreenChecksums?.layout !== newScreenChecksums?.layout
) {
logger.info(`Layout changed since last fetch.`);
logger.info(`Fetching layout.`);
newScreen.layoutData = await this.apiHelper.getPath(newScreen.layout);
} else {
// Get layout: Defines layout and regions.
logger.info(`Layout not changed since last fetch.`);
logger.info(`Layout loaded from cache.`);
newScreen.layoutData = this.lastestScreenData.layoutData;
}

// Fetch regions playlists: Yields playlists of slides for the regions
if (
relationChecksumEnabled === false ||
this.lastestScreenData?.hasActiveCampaign ||
oldScreenChecksums === null ||
oldScreenChecksums?.regions !== newScreenChecksums?.regions
) {
logger.info(`Regions changed since last fetch.`);
logger.info(`Fetching regions and slides for regions.`);
const regions = await this.getRegions(newScreen.regions);
newScreen.regionData = await this.getSlidesForRegions(regions);
} else {
logger.info(`Regions not changed since last fetch.`);
logger.info(`Regions and slides for regions loaded from cache.`);
newScreen.regionData = this.lastestScreenData.regionData;
}
}
Expand All @@ -308,7 +315,7 @@ class PullStrategy {

let previousSlide = null;

// Find slide in previous data for comparing relationsChecksum values.
// Find the slide in previous data for comparing relationsChecksum values.
if (
this.lastestScreenData?.regionData[regionKey] &&
this.lastestScreenData.regionData[regionKey][playlistKey] &&
Expand All @@ -328,6 +335,7 @@ class PullStrategy {

// Fetch template if it has changed.
if (
relationChecksumEnabled === false ||
oldSlideChecksums === null ||
newSlideChecksums.templateInfo !== oldSlideChecksums.templateInfo
) {
Expand All @@ -342,6 +350,7 @@ class PullStrategy {
) {
slide.templateData = fetchedTemplates[templatePath];
} else {
logger.info(`Fetching template data.`);
const templateData = await this.apiHelper.getPath(templatePath);
slide.templateData = templateData;

Expand All @@ -350,6 +359,7 @@ class PullStrategy {
}
}
} else {
logger.info(`Template data loaded from cache.`);
slide.templateData = previousSlide.templateData;
}

Expand All @@ -363,6 +373,7 @@ class PullStrategy {

// Fetch media if it has changed.
if (
relationChecksumEnabled === false ||
oldSlideChecksums === null ||
newSlideChecksums.media !== oldSlideChecksums.media
) {
Expand All @@ -372,6 +383,7 @@ class PullStrategy {
if (Object.prototype.hasOwnProperty.call(fetchedMedia, mediaId)) {
nextMediaData[mediaId] = fetchedMedia[mediaId];
} else {
logger.info(`Fetching media data.`);
const mediaData = await this.apiHelper.getPath(mediaId);
nextMediaData[mediaId] = mediaData;

Expand All @@ -383,11 +395,13 @@ class PullStrategy {

slide.mediaData = nextMediaData;
} else {
logger.info(`Media data loaded from cache.`);
slide.mediaData = previousSlide.mediaData;
}

// Fetch feed.
if (slide?.feed?.feedUrl !== undefined) {
logger.info(`Fetching feed data.`);
slide.feedData = await this.apiHelper.getPath(slide.feed.feedUrl);
}

Expand Down
5 changes: 5 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ services:
Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface: '@Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationFailureHandler'
Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface: '@Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler'

App\EventListener\RelationsChecksumListener:
arguments:
$enabled: '%env(bool:RELATIONS_CHECKSUM_ENABLED)%'

App\Controller\Admin\AdminConfigController:
arguments:
$rejseplanenApiKey: '%env(ADMIN_REJSEPLANEN_APIKEY)%'
Expand All @@ -70,6 +74,7 @@ services:
$pullStrategyInterval: '%env(int:CLIENT_PULL_STRATEGY_INTERVAL)%'
$colorScheme: '%env(json:CLIENT_COLOR_SCHEME)%'
$debug: '%env(bool:CLIENT_DEBUG)%'
$relationsChecksumEnabled: '%env(bool:RELATIONS_CHECKSUM_ENABLED)%'

App\Feed\EventDatabaseApiV2FeedType:
arguments:
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Client/ClientConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(
private readonly int $pullStrategyInterval,
private readonly array $colorScheme,
private readonly bool $debug,
private readonly bool $relationsChecksumEnabled,
) {}

public function __invoke(): Response
Expand All @@ -32,6 +33,7 @@ public function __invoke(): Response
'schedulingInterval' => $this->schedulingInterval,
'colorScheme' => $this->colorScheme,
'debug' => $this->debug,
'relationsChecksumEnabled' => $this->relationsChecksumEnabled,
]);
}
}
20 changes: 20 additions & 0 deletions src/EventListener/RelationsChecksumListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class RelationsChecksumListener
'playlist', 'screen_campaign', 'screen', 'screen_group_campaign', 'screen_group',
'playlist_screen_region', 'screen_layout_regions', 'screen_layout'];

public function __construct(
private readonly bool $enabled = false,
) {}

/**
* PrePersist listener.
*
Expand All @@ -73,6 +77,10 @@ class RelationsChecksumListener
*/
final public function prePersist(PrePersistEventArgs $args): void
{
if (!$this->enabled) {
return;
}

$entity = $args->getObject();

switch ($entity::class) {
Expand Down Expand Up @@ -162,6 +170,10 @@ final public function prePersist(PrePersistEventArgs $args): void
*/
final public function preUpdate(PreUpdateEventArgs $args): void
{
if (!$this->enabled) {
return;
}

$entity = $args->getObject();

if ($entity instanceof RelationsChecksumInterface) {
Expand All @@ -180,6 +192,10 @@ final public function preUpdate(PreUpdateEventArgs $args): void
*/
final public function preRemove(PreRemoveEventArgs $args): void
{
if (!$this->enabled) {
return;
}

$entity = $args->getObject();

switch ($entity::class) {
Expand Down Expand Up @@ -227,6 +243,10 @@ final public function preRemove(PreRemoveEventArgs $args): void
*/
final public function postFlush(PostFlushEventArgs $args): void
{
if (!$this->enabled) {
return;
}

$connection = $args->getObjectManager()->getConnection();

$sqlQueries = self::getUpdateRelationsAtQueries(withWhereClause: true);
Expand Down
Loading