Skip to content
Prev Previous commit
Next Next commit
Invalidate cache on delete/update function calls
(Nuclear option - clean the cache entirely)

Signed-off-by: Dariusz Olszewski <[email protected]>
  • Loading branch information
starypatyk committed Aug 17, 2022
commit 03f64768cc8219e7718980d7a6eef4d227b83de7
19 changes: 19 additions & 0 deletions lib/Share/RoomShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public function __construct(
$this->sharesByIdCache = new CappedMemoryCache();
}

/*
* Clean sharesByIdCache
*/
private function cleanSharesByIdCache() {
$this->sharesByIdCache = new CappedMemoryCache();
}

public static function register(IEventDispatcher $dispatcher): void {
$listener = static function (RoomEvent $event): void {
$room = $event->getRoom();
Expand Down Expand Up @@ -318,6 +325,8 @@ private function createShareObject(array $data): IShare {
* @return IShare The share object
*/
public function update(IShare $share): IShare {
$this->cleanSharesByIdCache();

$update = $this->dbConnection->getQueryBuilder();
$update->update('share')
->where($update->expr()->eq('id', $update->createNamedParameter($share->getId())))
Expand Down Expand Up @@ -361,6 +370,8 @@ public function update(IShare $share): IShare {
* @param IShare $share
*/
public function delete(IShare $share): void {
$this->cleanSharesByIdCache();

$delete = $this->dbConnection->getQueryBuilder();
$delete->delete('share')
->where($delete->expr()->eq('id', $delete->createNamedParameter($share->getId())));
Expand All @@ -380,6 +391,8 @@ public function delete(IShare $share): void {
* @param string $recipient UserId of the recipient
*/
public function deleteFromSelf(IShare $share, $recipient): void {
$this->cleanSharesByIdCache();

// Check if there is a userroom share
$qb = $this->dbConnection->getQueryBuilder();
$stmt = $qb->select(['id', 'permissions'])
Expand Down Expand Up @@ -432,6 +445,8 @@ public function deleteFromSelf(IShare $share, $recipient): void {
* @throws GenericShareException In case the share could not be restored
*/
public function restore(IShare $share, string $recipient): IShare {
$this->cleanSharesByIdCache();

$qb = $this->dbConnection->getQueryBuilder();
$qb->select('permissions')
->from('share')
Expand Down Expand Up @@ -472,6 +487,8 @@ public function restore(IShare $share, string $recipient): IShare {
* @return IShare
*/
public function move(IShare $share, $recipient): IShare {
$this->cleanSharesByIdCache();

// Check if there is a userroom share
$qb = $this->dbConnection->getQueryBuilder();
$stmt = $qb->select('id')
Expand Down Expand Up @@ -1110,6 +1127,8 @@ public function getChildren(IShare $parent): array {
* @param string|null $user
*/
public function deleteInRoom(string $roomToken, string $user = null): void {
$this->cleanSharesByIdCache();

//First delete all custom room shares for the original shares to be removed
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('id')
Expand Down