-
Notifications
You must be signed in to change notification settings - Fork 509
Reduce number of queries required to read shares #7743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
254e796
3e17b5c
03f6476
4c4f43a
e8bd174
78a4f65
31e130a
dcb7869
26497b4
aa9921d
e35b191
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
|
|
||
| namespace OCA\Talk\Share; | ||
|
|
||
| use OC\Cache\CappedMemoryCache; | ||
starypatyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| use OC\Files\Cache\Cache; | ||
| use OCA\Talk\Events\AlreadySharedEvent; | ||
| use OCA\Talk\Events\RoomEvent; | ||
|
|
@@ -83,6 +84,8 @@ class RoomShareProvider implements IShareProvider { | |
| private IL10N $l; | ||
| private IMimeTypeLoader $mimeTypeLoader; | ||
|
|
||
| private $sharesByIdCache; | ||
starypatyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public function __construct( | ||
| IDBConnection $connection, | ||
| ISecureRandom $secureRandom, | ||
|
|
@@ -103,6 +106,7 @@ public function __construct( | |
| $this->timeFactory = $timeFactory; | ||
| $this->l = $l; | ||
| $this->mimeTypeLoader = $mimeTypeLoader; | ||
| $this->sharesByIdCache = new CappedMemoryCache(); | ||
| } | ||
|
|
||
| public static function register(IEventDispatcher $dispatcher): void { | ||
|
|
@@ -631,6 +635,11 @@ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offs | |
| * @throws ShareNotFound | ||
| */ | ||
| public function getShareById($id, $recipientId = null): IShare { | ||
|
|
||
| if (isset($this->sharesByIdCache[$id])) { | ||
|
||
| return $this->sharesByIdCache[$id]; | ||
| } | ||
|
|
||
| $qb = $this->dbConnection->getQueryBuilder(); | ||
| $qb->select('s.*', | ||
| 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', | ||
|
|
@@ -665,6 +674,51 @@ public function getShareById($id, $recipientId = null): IShare { | |
| return $share; | ||
| } | ||
|
|
||
| /** | ||
| * Get shares by ids | ||
| * | ||
| * Not part of IShareProvider API, but needed by OCA\Talk\Controller\ChatController. | ||
| * | ||
| * @param int[] $id | ||
| * @param string|null $recipientId | ||
| * @return IShare[] | ||
| * @throws ShareNotFound | ||
| */ | ||
| public function getSharesByIds($ids, $recipientId = null): array { | ||
starypatyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $qb = $this->dbConnection->getQueryBuilder(); | ||
| $qb->select('s.*', | ||
| 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', | ||
| 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', | ||
| 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' | ||
| ) | ||
| ->selectAlias('st.id', 'storage_string_id') | ||
| ->from('share', 's') | ||
| ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) | ||
| ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) | ||
| ->where($qb->expr()->in('s.id', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) | ||
| ->andWhere($qb->expr()->eq('s.share_type', $qb->createNamedParameter(IShare::TYPE_ROOM))); | ||
|
|
||
| $cursor = $qb->executeQuery(); | ||
|
|
||
| $shares = []; | ||
| while ($data = $cursor->fetch()) { | ||
| $share = $this->createShareObject($data); | ||
| $id = (int) $share->getId(); | ||
| if (!isset($this->sharesByIdCache[$id])) { | ||
| $this->sharesByIdCache[$id] = $share; | ||
| } | ||
| $shares[] = $share; | ||
| } | ||
| $cursor->closeCursor(); | ||
|
|
||
| if ($recipientId !== null) { | ||
| return $this->resolveSharesForRecipient($shares, $recipientId); | ||
| } else { | ||
| return $shares; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns each given share as seen by the given recipient. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.