Skip to content

Commit

Permalink
Merge pull request #74 from erikn69/fix_single_tr
Browse files Browse the repository at this point in the history
[1.x] Fix df20593 bug
  • Loading branch information
masbug authored Jun 24, 2022
2 parents a27708b + 8afb3ff commit c42a6ed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/GoogleDriveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class GoogleDriveAdapter extends AbstractAdapter
'useHasDir' => false,
'useDisplayPaths' => true,
'usePermanentDelete' => false,
'useSinglePathTransaction' => false,
'publishPermission' => [
'type' => 'anyone',
'role' => 'reader',
Expand Down Expand Up @@ -160,6 +161,14 @@ class GoogleDriveAdapter extends AbstractAdapter
*/
private $usePermanentDelete = false;

/**
* When only needs to upload/download single file, is quick and
* avoid 'Timeout/Allowed memory exhausted' when too many files
*
* @var bool
*/
private $useSinglePathTransaction = false;

/**
* Options array
*
Expand Down Expand Up @@ -216,6 +225,7 @@ public function __construct($service, $root = null, $options = [])
$this->spaces = $this->options['spaces'];
$this->useHasDir = $this->options['useHasDir'];
$this->usePermanentDelete = $this->options['usePermanentDelete'];
$this->useSinglePathTransaction = $this->options['useSinglePathTransaction'];
$this->publishPermission = $this->options['publishPermission'];
$this->useDisplayPaths = $this->options['useDisplayPaths'];
$this->optParams = $this->cleanOptParameters($this->options['parameters']);
Expand Down Expand Up @@ -496,7 +506,7 @@ public function copy($path, $newpath)
if (isset($this->cacheHasDirs[$srcId])) {
$this->cacheHasDirs[$id] = $this->cacheHasDirs[$srcId];
}
if ($this->useDisplayPaths) {
if ($this->useSinglePathTransaction && $this->useDisplayPaths) {
$this->cachedPaths[trim($newpathDir.'/'.$fileName, '/')] = $id;
}

Expand Down Expand Up @@ -1435,7 +1445,7 @@ protected function upload($path, $contents, Config $config, $updating = null)
$this->cacheFileObjects[$obj->getId()] = $obj;
$this->cacheObjects([$obj->getId() => $obj]);
$result = $this->normaliseObject($obj, self::dirname($path));
if ($this->useDisplayPaths) {
if ($this->useSinglePathTransaction && $this->useDisplayPaths) {
$this->cachedPaths[$result['display_path']] = $obj->getId();
}

Expand Down Expand Up @@ -1782,7 +1792,9 @@ protected function cachePaths($displayPath, $i, $indices, $parentItemId)
}

$query = $is_last ? [] : ['mimeType = "'.self::DIRMIME.'"'];
$query[] = "name = '{$token}'";
if ($this->useSinglePathTransaction) {
$query[] = "name = '{$token}'";
}
$items[] = $this->getItems($id, false, 0, implode(' and ', $query));
if (DEBUG_ME) {
echo " ...done\n";
Expand Down

0 comments on commit c42a6ed

Please sign in to comment.