Skip to content

Commit

Permalink
index: support .nomemories (fix #777)
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Patil <radialapps@gmail.com>
  • Loading branch information
pulsejet committed Aug 20, 2023
1 parent ca8fad3 commit 0091fdd
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- **Feature**: Allow disabling autoplay of live photo ([#591](https://github.com/pulsejet/memories/issues/591))
- **Feature**: Improved layout for albums list view
- **Feature**: Improvements in admin interface
- **Feature**: A `.nomemories` file will now hide a folder from Memories without affecting other apps ([#777](https://github.com/pulsejet/memories/issues/777))
- **Bugfix**: You can now configure the transpose strategy of the transcoder (required for QSV)

## [v5.2.1] - 2023-07-03
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/MigrateGoogleTakeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function migrateUser(IUser $user): void
protected function migrateFolder(Folder $folder): void
{
// Check for .nomedia
if ($folder->nodeExists('.nomedia')) {
if ($folder->nodeExists('.nomedia') || $folder->nodeExists('.nomemories')) {
return;
}

Expand Down
9 changes: 7 additions & 2 deletions lib/Db/FsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Memories\Db;

use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OCA\Memories\Exceptions;
Expand All @@ -31,6 +32,7 @@
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\ICache;
use OCP\ICacheFactory;
Expand Down Expand Up @@ -152,10 +154,13 @@ public function getNoMediaFolders(Folder $root, string $key): array
return $paths;
}

$comp = new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', '.nomedia');
$comp = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', '.nomedia'),
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', '.nomemories'),
]);
$search = $root->search(new SearchQuery($comp, 0, 0, [], Util::getUser()));

$paths = array_map(fn (Node $node) => \dirname($node->getPath()), $search);
$paths = array_unique(array_map(fn (Node $node) => \dirname($node->getPath()), $search));
$this->nomediaCache->set($key, $paths, 60 * 60); // 1 hour

return $paths;
Expand Down
4 changes: 3 additions & 1 deletion lib/Db/TimelineQueryCTE.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ protected static function CTE_FOLDERS_ALL(bool $notArchive): string
$CLS_TOP_FOLDER = 'f.fileid IN (:topFolderIds)';

// Select 1 if there is a .nomedia file in the folder
$SEL_NOMEDIA = "SELECT 1 FROM *PREFIX*filecache f2 WHERE f2.parent = f.fileid AND f2.name = '.nomedia'";
$SEL_NOMEDIA = "SELECT 1 FROM *PREFIX*filecache f2
WHERE (f2.parent = f.fileid)
AND (f2.name = '.nomedia' OR f2.name = '.nomemories')";

// Check no nomedia file exists in the folder
$CLS_NOMEDIA = "NOT EXISTS ({$SEL_NOMEDIA})";
Expand Down
2 changes: 1 addition & 1 deletion lib/Listeners/PostWriteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function handle(Event $event): void
try {
$parent = $node;
while ($parent = $parent->getParent()) {
if ($parent->nodeExists('.nomedia')) {
if ($parent->nodeExists('.nomedia') || $parent->nodeExists('.nomemories')) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public function indexUser(string $uid, ?string $folder = null): void
*/
public function indexFolder(Folder $folder): void
{
if ($folder->nodeExists('.nomedia')) {
$this->log("Skipping folder {$folder->getPath()} due to .nomedia file\n", true);
if ($folder->nodeExists('.nomedia') || $folder->nodeExists('.nomemories')) {
$this->log("Skipping folder {$folder->getPath()} due to .nomedia or .nomemories file\n", true);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/admin/sections/Indexing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'The EXIF indexes are built and checked in a periodic background task. Be careful when selecting anything other than automatic indexing. For example, setting the indexing to only timeline folders may cause delays before media becomes available to users, since the user configures the timeline only after logging in.'
)
}}
{{ t('memories', 'Folders with a ".nomedia" file are always excluded from indexing.') }}
{{ t('memories', 'Folders with a ".nomedia" or a ".nomemories" file are always excluded from indexing.') }}
<NcCheckboxRadioSwitch
:checked.sync="config['memories.index.mode']"
value="1"
Expand Down

0 comments on commit 0091fdd

Please sign in to comment.