Skip to content

Commit

Permalink
cte: split nomedia subqueries
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Mar 30, 2024
1 parent 506865d commit 7c456f7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/Db/TimelineQueryCTE.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ protected function CTE_FOLDERS_ALL(bool $hidden): string
// Filter out folder MIME types
$FOLDER_MIME_QUERY = "SELECT MAX(id) FROM *PREFIX*mimetypes WHERE mimetype = 'httpd/unix-directory'";

// Select 1 if there is a .nomedia file in the folder
$SEL_NOMEDIA = "SELECT 1 FROM *PREFIX*filecache f2
// Select 1 if there is a file in the folder with the specified name
$SEL_FILE = static fn (string $name) => "SELECT 1 FROM *PREFIX*filecache f2
WHERE (f2.parent = f.fileid)
AND (f2.name = '.nomedia' OR f2.name = '.nomemories')";
AND (f2.name = '{$name}')";

// Check no nomedia file exists in the folder
$CLS_NOMEDIA = "NOT EXISTS ({$SEL_NOMEDIA})";
// Check for nomedia and nomemories files
// Two separate subqueries can actually be faster here (upto 10x on MariaDB)
$SEL_NOMEDIA = $SEL_FILE('.nomedia');
$SEL_NOMEMORIES = $SEL_FILE('.nomemories');
$CLS_NOMEDIA = "NOT EXISTS ({$SEL_NOMEDIA}) AND NOT EXISTS ({$SEL_NOMEMORIES})";

// Whether to filter out hidden folders
$CLS_HIDDEN_JOIN = $hidden ? '1 = 1' : "f.name NOT LIKE '.%'";
Expand Down

0 comments on commit 7c456f7

Please sign in to comment.