MDL-58219 googledocs: Use a cache

Speed up folder operations with a simple cache.

Part of MDL-58220
This commit is contained in:
Damyon Wiese 2017-03-10 14:12:00 +08:00
parent 6da1c55ba8
commit 39f60f6c00
4 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,41 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Googledocs repository cache definitions.
*
* This file is part of Moodle's cache API, affectionately called MUC.
* It contains the components that are requried in order to use caching.
*
* @package repository_googledocs
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$definitions = array(
// Used to store file ids for folders.
// The keys used are full path to the folder, the values are the id in google drive.
// The static acceleration size has been based upon the depths of a single path.
'folder' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => false,
'simpledata' => true,
'staticacceleration' => true,
'staticaccelerationsize' => 10,
'canuselocalstore' => true
),
);

View File

@ -47,3 +47,4 @@ $string['owner'] = 'Owned by: {$a}';
$string['oauthinfo'] = '<p>To use this plugin, you must register your site with Google, as described in the documentation <a href="{$a->docsurl}">Google OAuth 2.0 setup</a>.</p><p>As part of the registration process, you will need to enter the following URL as \'Authorized Redirect URIs\':</p><p>{$a->callbackurl}</p><p>Once registered, you will be provided with a client ID and secret which can be used to configure all Google Drive and Picasa plugins.</p><p>Please also note that you will have to enable the service \'Drive API\'.</p>';
$string['secret'] = 'Secret';
$string['clientid'] = 'Client ID';
$string['cachedef_folder'] = 'Google File IDs for folders in the system account';

View File

@ -1022,17 +1022,25 @@ class repository_googledocs extends repository {
// Now move it to a sensible folder.
$contextlist = array_reverse($context->get_parent_contexts(true));
$cache = cache::make('repository_googledocs', 'folder');
$parentid = 'root';
$fullpath = 'root';
foreach ($contextlist as $context) {
// Make sure a folder exists here.
$foldername = $context->get_context_name();
$fullpath .= '/' . $foldername;
$folderid = $this->folder_exists_in_folder($systemservice, $foldername, $parentid);
$folderid = $cache->get('fullpath');
if (empty($folderid)) {
$folderid = $this->folder_exists_in_folder($systemservice, $foldername, $parentid);
}
if ($folderid !== false) {
$cache->set($fullpath, $folderid);
$parentid = $folderid;
} else {
// Create it.
$parentid = $this->create_folder_in_folder($systemservice, $foldername, $parentid);
$cache->set($fullpath, $parentid);
}
}

View File

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017030600; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2017031001; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2016112900; // Requires this Moodle version.
$plugin->component = 'repository_googledocs'; // Full name of the plugin (used for diagnostics).