Skip to content

Commit

Permalink
More optimizations on OCS API Calls
Browse files Browse the repository at this point in the history
Share ID is already returned when inserting the share into the database,
no need to retrieve it later.
  • Loading branch information
nadir committed Mar 2, 2016
1 parent 372cdf9 commit cbda773
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions apps/files_sharing/api/customlocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static function createShare($params)
}

$token = 0;

$id = false;
try {
if(!$executor->checkFileIntegrity())
{
Expand All @@ -147,7 +147,7 @@ public static function createShare($params)
throw new \Exception('Check share target failed');
}

$executor->insertShare();
$id = $executor->insertShare();
$token = $executor->getInsertResult();

} catch (\Exception $e) {
Expand All @@ -157,39 +157,15 @@ public static function createShare($params)
if($token)
{
$data = [];
$username = \OCP\User::getUser();
$queryStorages = \OC_DB::prepare('SELECT numeric_id FROM oc_storages WHERE id = ?');
$resultStorages = $queryStorages->execute(['object::user:'.$username]);
$storageId = $resultStorages->fetchRow()['numeric_id'];

$rows = [];
$data['id'] = $id;
if(is_string($token))
{
$query = \OC_DB::prepare('SELECT * FROM oc_share WHERE token = ?');
$result = $query->execute([$token]);
$rows = $result->fetchAll();
}
else
{
$rows = self::getAllFilesSharedByMe();
}

foreach($rows as $key => $row)
{
// Only return information if the asker is the same person who shared the file
if($token === $row['token'] || ($share['share_with'] === $shareWith && $share['share_type'] === $shareType))
{
$data['id'] = $row['id'];
if(is_string($token))
{
$url = \OCP\Util::linkToPublic('files&t='.$token);
$data['url'] = $url; // '&' gets encoded to $amp;
$data['token'] = $token;
}

return new \OC_OCS_Result([$data]);
}
$url = \OCP\Util::linkToPublic('files&t='.$token);
$data['url'] = $url; // '&' gets encoded to $amp;
$data['token'] = $token;
}

return new \OC_OCS_Result([$data]);
}
else
{
Expand Down

0 comments on commit cbda773

Please sign in to comment.