@@ -114,22 +114,20 @@ public function getByAncestorInStorage(int $storageId, int $folderId, int $fileI
114
114
115
115
$ path = $ root ['path ' ] === '' ? '' : $ root ['path ' ] . '/ ' ;
116
116
117
- $ qb ->selectDistinct ('* ' )
117
+ $ qb ->selectDistinct ('f. * ' )
118
118
->from ('filecache ' , 'f ' )
119
119
->where ($ qb ->expr ()->like ('f.path ' , $ qb ->createNamedParameter ($ this ->connection ->escapeLikeParameter ($ path ) . '% ' )))
120
120
->andWhere ($ qb ->expr ()->eq ('f.storage ' , $ qb ->createNamedParameter ($ storageId )))
121
- ->andWhere ($ qb ->expr ()->gt ('f.fileid ' , $ qb ->createNamedParameter ($ fileIdCursor , IQueryBuilder::PARAM_INT )));
121
+ ->andWhere ($ qb ->expr ()->gt ('f.fileid ' , $ qb ->createNamedParameter ($ fileIdCursor , IQueryBuilder::PARAM_INT )))
122
+ ->hintShardKey ('storage ' , $ storageId );
122
123
123
- if (!$ endToEndEncrypted ) {
124
+ if (!$ endToEndEncrypted && $ this -> connection -> getShardDefinition ( ' filecache ' ) === null ) {
124
125
// End to end encrypted files are descendants of a folder with encrypted=1
125
- // Use a subquery to check the `encrypted` status of the parent folder
126
- $ subQuery = $ this ->getQuery ()->select ('p.encrypted ' )
127
- ->from ('filecache ' , 'p ' )
128
- ->andWhere ($ qb ->expr ()->eq ('p.fileid ' , 'f.parent ' ))
129
- ->getSQL ();
126
+ // We can only do this inner join if the filecache table is not sharded
127
+ $ qb ->innerJoin ('f ' , 'filecache ' , 'f2 ' , $ qb ->expr ()->eq ('f2.fileid ' , 'f.parent ' ));
130
128
131
129
$ qb ->andWhere (
132
- $ qb ->expr ()->eq ($ qb -> createFunction ( sprintf ( ' (%s) ' , $ subQuery )) , $ qb ->createNamedParameter (0 , IQueryBuilder::PARAM_INT ))
130
+ $ qb ->expr ()->eq (' f2.encrypted ' , $ qb ->createNamedParameter (0 , IQueryBuilder::PARAM_INT ))
133
131
);
134
132
}
135
133
@@ -152,6 +150,21 @@ public function getByAncestorInStorage(int $storageId, int $folderId, int $fileI
152
150
/** @var array */
153
151
$ row = $ files ->fetch ()
154
152
) {
153
+ if (!$ endToEndEncrypted && $ this ->connection ->getShardDefinition ('filecache ' ) !== null ) {
154
+ // End to end encrypted files are descendants of a folder with encrypted=1
155
+ // If the filecache table is sharded we need to check individually if the parent is encrypted
156
+ $ parentQuery = $ this ->getQuery ();
157
+ $ parentQuery ->select ('encrypted ' )->from ('filecache ' );
158
+ $ parentQuery ->whereFileId ($ row ['parent ' ]);
159
+ $ parentQuery ->hintShardKey ('storage ' , $ storageId );
160
+ $ parentQuery ->setMaxResults (1 );
161
+ $ result = $ parentQuery ->executeQuery ();
162
+ $ encrypted = $ result ->fetchOne ();
163
+ $ result ->closeCursor ();
164
+ if ($ encrypted === 1 ) {
165
+ continue ;
166
+ }
167
+ }
155
168
yield Cache::cacheEntryFromData ($ row , $ this ->mimeTypeLoader );
156
169
}
157
170
0 commit comments