Skip to content

Commit 19e521e

Browse files
authored
Merge pull request #35844 from nextcloud/debt/noid/add-explanation-for-get-new-preview-locations
doc: add description how BackgroundCleanupJob.getNewPreviewLocations works
2 parents dc7e2fb + 71a6030 commit 19e521e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/private/Preview/BackgroundCleanupJob.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ private function getNewPreviewLocations(): \Iterator {
128128
*/
129129
$like = $this->connection->escapeLikeParameter($data['path']) . '/_/_/_/_/_/_/_/%';
130130

131+
/*
132+
* Deleting a file will not delete related previews right away.
133+
*
134+
* A delete request is usually an HTTP request.
135+
* The preview deleting is done by a background job to avoid timeouts.
136+
*
137+
* Previews for a file are stored within a folder in appdata_/preview using the fileid as folder name.
138+
* Preview folders in oc_filecache are identified by a.storage, a.path (cf. $like) and a.mimetype.
139+
*
140+
* To find preview folders to delete, we query oc_filecache for a preview folder in app data, matching the preview folder structure
141+
* and use the name to left join oc_filecache on a.name = b.fileid. A left join returns all rows from the left table (a),
142+
* even if there are no matches in the right table (b).
143+
*
144+
* If the related file is deleted, b.fileid will be null and the preview folder can be deleted.
145+
*/
131146
$qb = $this->connection->getQueryBuilder();
132147
$qb->select('a.name')
133148
->from('filecache', 'a')

0 commit comments

Comments
 (0)