2323
2424namespace OCA \Deck \Db ;
2525
26- use OC \Cache \CappedMemoryCache ;
2726use OCA \Deck \Service \CirclesService ;
2827use OCP \AppFramework \Db \DoesNotExistException ;
2928use OCP \AppFramework \Db \QBMapper ;
29+ use OCP \Cache \CappedMemoryCache ;
3030use OCP \DB \QueryBuilder \IQueryBuilder ;
3131use OCP \IDBConnection ;
3232use OCP \IGroupManager ;
3535
3636/** @template-extends QBMapper<Board> */
3737class BoardMapper extends QBMapper implements IPermissionMapper {
38- private $ labelMapper ;
39- private $ aclMapper ;
40- private $ stackMapper ;
41- private $ userManager ;
42- private $ groupManager ;
43- private $ circlesService ;
44- private $ logger ;
45-
4638 /** @var CappedMemoryCache<Board[]> */
47- private $ userBoardCache ;
39+ private CappedMemoryCache $ userBoardCache ;
4840 /** @var CappedMemoryCache<Board> */
49- private $ boardCache ;
41+ private CappedMemoryCache $ boardCache ;
5042
5143 public function __construct (
5244 IDBConnection $ db ,
53- LabelMapper $ labelMapper ,
54- AclMapper $ aclMapper ,
55- StackMapper $ stackMapper ,
56- IUserManager $ userManager ,
57- IGroupManager $ groupManager ,
58- CirclesService $ circlesService ,
59- LoggerInterface $ logger
45+ private LabelMapper $ labelMapper ,
46+ private AclMapper $ aclMapper ,
47+ private StackMapper $ stackMapper ,
48+ private IUserManager $ userManager ,
49+ private IGroupManager $ groupManager ,
50+ private CirclesService $ circlesService ,
51+ private LoggerInterface $ logger
6052 ) {
6153 parent ::__construct ($ db , 'deck_boards ' , Board::class);
62- $ this ->labelMapper = $ labelMapper ;
63- $ this ->aclMapper = $ aclMapper ;
64- $ this ->stackMapper = $ stackMapper ;
65- $ this ->userManager = $ userManager ;
66- $ this ->groupManager = $ groupManager ;
67- $ this ->circlesService = $ circlesService ;
68- $ this ->logger = $ logger ;
6954
7055 $ this ->userBoardCache = new CappedMemoryCache ();
7156 $ this ->boardCache = new CappedMemoryCache ();
@@ -81,30 +66,31 @@ public function __construct(
8166 * @throws DoesNotExistException
8267 */
8368 public function find (int $ id , bool $ withLabels = false , bool $ withAcl = false , bool $ allowDeleted = false ): Board {
84- if (!isset ($ this ->boardCache [$ id ])) {
69+ $ cacheKey = (string )$ id ;
70+ if (!isset ($ this ->boardCache [$ cacheKey ])) {
8571 $ qb = $ this ->db ->getQueryBuilder ();
8672 $ deletedWhere = $ allowDeleted ? $ qb ->expr ()->gte ('deleted_at ' , $ qb ->createNamedParameter (0 , IQueryBuilder::PARAM_INT )) : $ qb ->expr ()->eq ('deleted_at ' , $ qb ->createNamedParameter (0 , IQueryBuilder::PARAM_INT ));
8773 $ qb ->select ('* ' )
8874 ->from ('deck_boards ' )
8975 ->where ($ qb ->expr ()->eq ('id ' , $ qb ->createNamedParameter ($ id , IQueryBuilder::PARAM_INT )))
9076 ->andWhere ($ deletedWhere )
9177 ->orderBy ('id ' );
92- $ this ->boardCache [$ id ] = $ this ->findEntity ($ qb );
78+ $ this ->boardCache [( string ) $ id ] = $ this ->findEntity ($ qb );
9379 }
9480
9581 // Add labels
96- if ($ withLabels && $ this ->boardCache [$ id ]->getLabels () === null ) {
82+ if ($ withLabels && $ this ->boardCache [$ cacheKey ]->getLabels () === null ) {
9783 $ labels = $ this ->labelMapper ->findAll ($ id );
98- $ this ->boardCache [$ id ]->setLabels ($ labels );
84+ $ this ->boardCache [$ cacheKey ]->setLabels ($ labels );
9985 }
10086
10187 // Add acl
102- if ($ withAcl && $ this ->boardCache [$ id ]->getAcl () === null ) {
88+ if ($ withAcl && $ this ->boardCache [$ cacheKey ]->getAcl () === null ) {
10389 $ acl = $ this ->aclMapper ->findAll ($ id );
104- $ this ->boardCache [$ id ]->setAcl ($ acl );
90+ $ this ->boardCache [$ cacheKey ]->setAcl ($ acl );
10591 }
10692
107- return $ this ->boardCache [$ id ];
93+ return $ this ->boardCache [$ cacheKey ];
10894 }
10995
11096 public function findBoardIds (string $ userId ): array {
@@ -464,8 +450,7 @@ public function findBoardId($id): ?int {
464450 }
465451
466452 public function mapAcl (Acl &$ acl ) {
467- $ groupManager = $ this ->groupManager ;
468- $ acl ->resolveRelation ('participant ' , function ($ participant ) use (&$ acl , &$ userManager , &$ groupManager ) {
453+ $ acl ->resolveRelation ('participant ' , function ($ participant ) use (&$ acl ) {
469454 if ($ acl ->getType () === Acl::PERMISSION_TYPE_USER ) {
470455 if ($ this ->userManager ->userExists ($ acl ->getParticipant ())) {
471456 return new User ($ acl ->getParticipant (), $ this ->userManager );
@@ -474,7 +459,7 @@ public function mapAcl(Acl &$acl) {
474459 return null ;
475460 }
476461 if ($ acl ->getType () === Acl::PERMISSION_TYPE_GROUP ) {
477- $ group = $ groupManager ->get ($ participant );
462+ $ group = $ this -> groupManager ->get ($ participant );
478463 if ($ group !== null ) {
479464 return new Group ($ group );
480465 }
0 commit comments