Skip to content
Prev Previous commit
Next Next commit
fix: Avoid triggering several activities for Range request on the sam…
…e file

Avoids flooding activities when someone browse a video in the web player.

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Mar 27, 2025
commit 0c293b35695848002bd24d1bba10962cbfe5ca3b
12 changes: 10 additions & 2 deletions apps/files_sharing/lib/Listener/BeforeNodeReadListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\ISession;
use OCP\Share\IShare;

/**
Expand All @@ -32,7 +32,7 @@ class BeforeNodeReadListener implements IEventListener {
private ICache $cache;

public function __construct(
private IUserSession $userSession,
private ISession $session,
private IRootFolder $rootFolder,
private \OCP\Activity\IManager $activityManager,
private IRequest $request,
Expand Down Expand Up @@ -113,6 +113,14 @@ public function handleBeforeNodeReadEvent(BeforeNodeReadEvent $event): void {
return;
}

/* Avoid publishing several activities for one video playing */
$cacheKey = $node->getId() . $node->getPath();
if (($this->request->getHeader('range') !== '') && ($this->cache->get($cacheKey) == $this->session->getId())) {
/* This is a range request and an activity for the same file was published in the same session */
return;
}
$this->cache->set($cacheKey, $this->session->getId(), 3600);

$this->singleFileDownloaded($share, $node);
}

Expand Down