9
9
use App \Domain \PlanningDomain ;
10
10
use App \Domain \SkillSetDomain ;
11
11
use App \Entity \CommissionableAsset ;
12
+ use Psr \Cache \CacheItemPoolInterface ;
12
13
use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
14
+ use Symfony \Component \Cache \CacheItem ;
13
15
use Symfony \Component \HttpFoundation \Request ;
14
16
use Symfony \Component \HttpFoundation \Response ;
15
17
use Symfony \Component \Routing \Annotation \Route ;
18
+ use Twig \CacheExtension \CacheStrategyInterface ;
16
19
17
20
/**
18
21
* @Route("/", name="planning", methods={"GET"})
@@ -21,13 +24,19 @@ class PlanningController extends AbstractController
21
24
{
22
25
private SkillSetDomain $ skillSetDomain ;
23
26
private PlanningDomain $ planningDomain ;
27
+ private CacheStrategyInterface $ cacheStrategy ;
28
+ private CacheItemPoolInterface $ cacheTwig ;
24
29
25
30
public function __construct (
26
31
SkillSetDomain $ skillSetDomain ,
27
- PlanningDomain $ planningDomain
32
+ PlanningDomain $ planningDomain ,
33
+ CacheStrategyInterface $ cacheStrategy ,
34
+ CacheItemPoolInterface $ cacheTwig
28
35
) {
29
36
$ this ->skillSetDomain = $ skillSetDomain ;
30
37
$ this ->planningDomain = $ planningDomain ;
38
+ $ this ->cacheStrategy = $ cacheStrategy ;
39
+ $ this ->cacheTwig = $ cacheTwig ;
31
40
}
32
41
33
42
public function __invoke (Request $ request ): Response
@@ -46,12 +55,22 @@ public function __invoke(Request $request): Response
46
55
$ filters ['to ' ]
47
56
);
48
57
49
- $ availabilities = $ this ->planningDomain ->generateAvailabilities ($ filters , $ periodCalculator ->getPeriod ());
58
+ $ lastUpdate = $ this ->planningDomain ->generateLastUpdateAndCount ($ filters )['lastUpdate ' ];
59
+ $ cacheKey = $ this ->cacheStrategy ->generateKey ('organization_planning ' , $ filters );
60
+ /** @var CacheItem $item */
61
+ $ item = $ this ->cacheTwig ->getItem ($ cacheKey );
62
+ if ($ item ->isHit ()
63
+ && isset ($ item ->getMetadata ()[CacheItem::METADATA_CTIME ])
64
+ && $ item ->getMetadata ()[CacheItem::METADATA_CTIME ] < ceil ($ lastUpdate / 100 )
65
+ ) {
66
+ // New availabilities in planning: invalidate planning cache
67
+ $ this ->cacheTwig ->deleteItem ($ cacheKey );
68
+ }
50
69
51
70
return $ this ->render ('organization/planning/planning.html.twig ' , [
71
+ 'filters ' => $ filters ,
52
72
'form ' => $ form ->createView (),
53
73
'periodCalculator ' => $ periodCalculator ,
54
- 'availabilities ' => $ availabilities ,
55
74
'assetsTypes ' => CommissionableAsset::TYPES ,
56
75
'usersSkills ' => $ this ->skillSetDomain ->getSkillSet (),
57
76
'importantSkills ' => $ this ->skillSetDomain ->getImportantSkills (),
0 commit comments