@@ -31,6 +31,10 @@ class ContentHandler extends AbstractInMemoryPersistenceHandler implements Conte
3131 private const CONTENT_VERSION_LIST_IDENTIFIER = 'content_version_list ' ;
3232 private const CONTENT_VERSION_INFO_IDENTIFIER = 'content_version_info ' ;
3333 private const CONTENT_VERSION_IDENTIFIER = 'content_version ' ;
34+ private const CONTENT_RELATIONS_COUNT_WITH_VERSION_TYPE_IDENTIFIER = 'content_relations_count_with_by_version_type_suffix ' ;
35+ private const CONTENT_RELATION_IDENTIFIER = 'content_relation ' ;
36+ private const CONTENT_RELATIONS_LIST_IDENTIFIER = 'content_relations_list ' ;
37+ private const CONTENT_RELATIONS_LIST_WITH_VERSION_TYPE_IDENTIFIER = 'content_relations_list_with_by_version_type_suffix ' ;
3438 private const CONTENT_REVERSE_RELATIONS_COUNT_IDENTIFIER = 'content_reverse_relations_count ' ;
3539 private const RELATION_IDENTIFIER = 'relation ' ;
3640
@@ -517,6 +521,97 @@ public function loadRelations($sourceContentId, $sourceContentVersionNo = null,
517521 return $ this ->persistenceHandler ->contentHandler ()->loadRelations ($ sourceContentId , $ sourceContentVersionNo , $ type );
518522 }
519523
524+ public function countRelations (int $ sourceContentId , ?int $ sourceContentVersionNo = null , ?int $ type = null ): int
525+ {
526+ $ cacheItem = $ this ->cache ->getItem (
527+ $ this ->cacheIdentifierGenerator ->generateKey (
528+ self ::CONTENT_RELATIONS_COUNT_WITH_VERSION_TYPE_IDENTIFIER ,
529+ [$ sourceContentId , $ sourceContentVersionNo , $ type ],
530+ true
531+ )
532+ );
533+
534+ if ($ cacheItem ->isHit ()) {
535+ $ this ->logger ->logCacheHit (['content ' => $ sourceContentId , 'version ' => $ sourceContentVersionNo , 'type ' => $ type ]);
536+
537+ return $ cacheItem ->get ();
538+ }
539+
540+ $ this ->logger ->logCacheMiss (['content ' => $ sourceContentId , 'version ' => $ sourceContentVersionNo , 'type ' => $ type ]);
541+ $ relationsCount = $ this ->persistenceHandler ->contentHandler ()->countRelations (
542+ $ sourceContentId ,
543+ $ sourceContentVersionNo ,
544+ $ type
545+ );
546+ $ cacheItem ->set ($ relationsCount );
547+ $ tags = [
548+ $ this ->cacheIdentifierGenerator ->generateTag (
549+ self ::CONTENT_IDENTIFIER ,
550+ [$ sourceContentId ]
551+ ),
552+ ];
553+
554+ $ cacheItem ->tag ($ tags );
555+ $ this ->cache ->save ($ cacheItem );
556+
557+ return $ relationsCount ;
558+ }
559+
560+ public function loadRelationList (
561+ int $ sourceContentId ,
562+ int $ limit ,
563+ int $ offset = 0 ,
564+ ?int $ sourceContentVersionNo = null ,
565+ ?int $ type = null
566+ ): array {
567+ return $ this ->getListCacheValue (
568+ $ this ->cacheIdentifierGenerator ->generateKey (
569+ self ::CONTENT_RELATIONS_LIST_WITH_VERSION_TYPE_IDENTIFIER ,
570+ [$ sourceContentId , $ limit , $ offset , $ sourceContentVersionNo , $ type ],
571+ true
572+ ),
573+ function () use ($ sourceContentId , $ limit , $ offset , $ sourceContentVersionNo , $ type ): array {
574+ return $ this ->persistenceHandler ->contentHandler ()->loadRelationList (
575+ $ sourceContentId ,
576+ $ limit ,
577+ $ offset ,
578+ $ sourceContentVersionNo ,
579+ $ type
580+ );
581+ },
582+ function (Relation $ relation ): array {
583+ return [
584+ $ this ->cacheIdentifierGenerator ->generateTag (
585+ self ::CONTENT_RELATION_IDENTIFIER ,
586+ [$ relation ->destinationContentId ]
587+ ),
588+ $ this ->cacheIdentifierGenerator ->generateTag (
589+ self ::CONTENT_IDENTIFIER ,
590+ [$ relation ->destinationContentId ]
591+ ),
592+ ];
593+ },
594+ function (Relation $ relation ): array {
595+ return [
596+ $ this ->cacheIdentifierGenerator ->generateKey (self ::CONTENT_IDENTIFIER , [$ relation ->destinationContentId ], true ),
597+ ];
598+ },
599+ function () use ($ sourceContentId ): array {
600+ return [
601+ $ this ->cacheIdentifierGenerator ->generateTag (
602+ self ::CONTENT_RELATIONS_LIST_IDENTIFIER ,
603+ [$ sourceContentId ]
604+ ),
605+ $ this ->cacheIdentifierGenerator ->generateTag (
606+ self ::CONTENT_IDENTIFIER ,
607+ [$ sourceContentId ]
608+ ),
609+ ];
610+ },
611+ [$ sourceContentId , $ limit , $ offset , $ sourceContentVersionNo , $ type ]
612+ );
613+ }
614+
520615 /**
521616 * {@inheritdoc}
522617 */
0 commit comments