Skip to content

Commit

Permalink
Cache nomedia paths on server and load via initialState
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Jan 26, 2022
1 parent 68adffe commit 1878e80
Show file tree
Hide file tree
Showing 50 changed files with 141 additions and 198 deletions.
4 changes: 2 additions & 2 deletions js/photos-main.js

Large diffs are not rendered by default.

45 changes: 1 addition & 44 deletions js/photos-main.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@
* @license MIT
*/

/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Vue.js v2.6.14
* (c) 2014-2021 Evan You
Expand All @@ -86,14 +79,6 @@
* Copyright (c) 2016 Jorik Tangelder;
* Licensed under the MIT license */

/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */

/*! https://mths.be/he v1.2.0 by @mathias | MIT license */

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @copyright 2019 Christoph Wurst <[email protected]>
*
Expand Down Expand Up @@ -134,6 +119,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
Expand Down Expand Up @@ -180,27 +166,6 @@
*
*/

/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
*
Expand Down Expand Up @@ -312,14 +277,6 @@
*
*/

/**
* @license nested-property https://github.com/cosmosio/nested-property
*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Olivier Scherrer <[email protected]>
*/

/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.16.1
Expand Down
2 changes: 1 addition & 1 deletion js/photos-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
Expand All @@ -38,4 +39,5 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions js/photos-src_patchedRequest_js-src_views_Tags_vue.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
1 change: 1 addition & 0 deletions js/photos-src_patchedRequest_js-src_views_Tags_vue.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/photos-src_views_Albums_vue.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
2 changes: 1 addition & 1 deletion js/photos-src_views_Albums_vue.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions js/photos-src_views_Tags_vue.js

This file was deleted.

1 change: 0 additions & 1 deletion js/photos-src_views_Tags_vue.js.map

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */

/*! https://mths.be/he v1.2.0 by @mathias | MIT license */

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @license nested-property https://github.com/cosmosio/nested-property
*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Olivier Scherrer <[email protected]>
*/

Large diffs are not rendered by default.

62 changes: 56 additions & 6 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace OCA\Photos\Controller;

use OC\User\NoUserException;
use OCA\Files\Event\LoadSidebar;
use OCA\Photos\AppInfo\Application;
use OCA\Viewer\Event\LoadViewer;
Expand All @@ -33,11 +34,18 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Util;
use Psr\Log\LoggerInterface;

class PageController extends Controller {
/** @var IAppManager */
Expand All @@ -54,20 +62,43 @@ class PageController extends Controller {

/** @var IUserSession */
private $userSession;
/**
* @var \OCP\Files\IRootFolder
*/
private $rootFolder;
/**
* @var \OCP\ICacheFactory
*/
private $cacheFactory;
/**
* @var \OCP\ICache
*/
private $nomediaPathsCache;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;

public function __construct(IRequest $request,
IAppManager $appManager,
IEventDispatcher $eventDispatcher,
IConfig $config,
public function __construct(IRequest $request,
IAppManager $appManager,
IEventDispatcher $eventDispatcher,
IConfig $config,
IInitialStateService $initialStateService,
IUserSession $userSession) {
IUserSession $userSession,
IRootFolder $rootFolder,
ICacheFactory $cacheFactory,
LoggerInterface $logger) {
parent::__construct(Application::APP_ID, $request);

$this->appManager = $appManager;
$this->eventDispatcher = $eventDispatcher;
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->userSession = $userSession;
$this->rootFolder = $rootFolder;
$this->cacheFactory = $cacheFactory;
$this->nomediaPathsCache = $this->cacheFactory->createLocal('photos:nomedia-paths');
$this->logger = $logger;
}

/**
Expand All @@ -89,6 +120,25 @@ public function index(): TemplateResponse {
$this->initialStateService->provideInitialState($this->appName, 'croppedLayout', $this->config->getUserValue($user->getUid(), Application::APP_ID, 'croppedLayout', 'false'));
$this->initialStateService->provideInitialState($this->appName, 'systemtags', $this->appManager->isEnabledForUser('systemtags') === true);

$paths = [];
try {
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$key = $user->getUID() . ':' . $userFolder->getEtag();
$paths = $this->nomediaPathsCache->get($key);
if ($paths === null) {
$nomedia = $userFolder->search('.nomedia');
$noimage = $userFolder->search('.noimage');
$paths = array_map(function (Node $node) use ($userFolder) {
return substr(dirname($node->getPath()), strlen($userFolder->getPath()));
}, $nomedia + $noimage);
$this->nomediaPathsCache->set($key, $paths, 60 * 60 * 24 * 28);
}
} catch (InvalidPathException | NotFoundException | NotPermittedException | NoUserException $e) {
$this->logger->error($e);
}

$this->initialStateService->provideInitialState($this->appName, 'nomedia-paths', $paths);

Util::addScript(Application::APP_ID, 'photos-main');
Util::addStyle(Application::APP_ID, 'icons');

Expand All @@ -98,7 +148,7 @@ public function index(): TemplateResponse {
$policy->addAllowedWorkerSrcDomain("'self'");
$policy->addAllowedScriptDomain("'self'");
$response->setContentSecurityPolicy($policy);

return $response;
}
}
6 changes: 3 additions & 3 deletions src/Photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<script>
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'

import Content from '@nextcloud/vue/dist/Components/Content'
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
Expand All @@ -78,7 +79,6 @@ import imgplaceholder from './assets/image.svg'
import videoplaceholder from './assets/video.svg'
import isMapsInstalled from './services/IsMapsInstalled'
import areTagsInstalled from './services/AreTagsInstalled'
import searchNomedia from './services/NomediaSearch'

export default {
name: 'Photos',
Expand Down Expand Up @@ -120,8 +120,8 @@ export default {
console.debug('Service Worker is not enabled on this browser.')
}

const files = await searchNomedia({ full: true })
this.$store.dispatch('setNomediaFiles', files)
const files = loadState('photos', 'nomedia-paths', [])
this.$store.dispatch('setNomediaPaths', files)
},

beforeDestroy() {
Expand Down
1 change: 1 addition & 0 deletions src/assets/grid-sizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

// for now we want to keep the same gap everywhere
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { generateFilePath } from '@nextcloud/router'
Expand Down
1 change: 1 addition & 0 deletions src/mixins/GridConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import getGridConfig from '../services/GridConfig'
Expand Down
1 change: 1 addition & 0 deletions src/mixins/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
Expand Down
1 change: 1 addition & 0 deletions src/patchedRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

const request = require('webdav/dist/node/request')
Expand Down
1 change: 1 addition & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { generateUrl } from '@nextcloud/router'
Expand Down
1 change: 1 addition & 0 deletions src/services/AlbumContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import axios from '@nextcloud/axios'
Expand Down
1 change: 1 addition & 0 deletions src/services/AllowedMimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { loadState } from '@nextcloud/initial-state'
Expand Down
1 change: 1 addition & 0 deletions src/services/AreTagsInstalled.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { loadState } from '@nextcloud/initial-state'
Expand Down
1 change: 1 addition & 0 deletions src/services/DavClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import webdav from 'webdav'
Expand Down
1 change: 1 addition & 0 deletions src/services/DavRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
const props = `
<oc:fileid />
Expand Down
1 change: 1 addition & 0 deletions src/services/FileList.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { getCurrentUser } from '@nextcloud/auth'
Expand Down
1 change: 1 addition & 0 deletions src/services/FolderInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { getCurrentUser } from '@nextcloud/auth'
Expand Down
1 change: 1 addition & 0 deletions src/services/GridConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import Vue from 'vue'
Expand Down
1 change: 1 addition & 0 deletions src/services/IsMapsInstalled.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { loadState } from '@nextcloud/initial-state'
Expand Down
Loading

0 comments on commit 1878e80

Please sign in to comment.