diff --git a/js/script.js b/js/script.js index 9eb1cb8..2c2d7a3 100644 --- a/js/script.js +++ b/js/script.js @@ -2,13 +2,23 @@ var nmcFilesActvityAction = (function () { var delActvities = function() { $('.del-files-activity').click(function(){ + $(".del-files-activity button").attr("disabled", true); $.ajax({ url: OC.generateUrl('/apps/nmc_files_activity/deleteActivitiesCustom'), type: 'DELETE', success: function(response, status, xhr) { - location.reload(); - } + $(".del-files-activity button").attr("disabled", false); + var filter = 'all'; + OC.Util.History.pushState({ + filter: filter + }); + OCA.Activity.Filter.setFilter(filter); + }, + error: function (jqXHR, exception) { + $(".del-files-activity button").attr("disabled", false); + }, }); + }); }; @@ -20,7 +30,7 @@ } })(); - nmcFilesActvityAction.delActvities(); + nmcFilesActvityAction.delActvities(); }); diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 98bded6..0fb84cd 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -14,16 +14,42 @@ use OCP\Activity\IManager; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\ICache; +use OCP\ICacheFactory; +use OCP\IURLGenerator; +use OCP\ILogger; +use OCP\IMemcache; +use OC\Memcache\NullCache; + class PageController extends Controller { private $userId; /** @var IDBConnection */ protected $connection; - public function __construct($AppName, IRequest $request, $UserId, IDBConnection $connection){ + /** @var ICacheFactory */ + private $cacheFactory; + + /** @var IMemcache */ + private $lockingCache; + + /** @var IURLGenerator */ + protected $urlGenerator; + + /** @var ILogger */ + protected $logger; + + public function __construct($AppName, IRequest $request, $UserId, IDBConnection $connection, IURLGenerator $urlGenerator, ICacheFactory $cacheFactory, ILogger $logger,){ parent::__construct($AppName, $request); $this->userId = $UserId; $this->connection = $connection; + $this->urlGenerator = $urlGenerator; + $this->logger = $logger; + $lockingCache = $cacheFactory->createDistributed('Activity-locks'); + if (!($lockingCache instanceof IMemcache)) { + $lockingCache = new NullCache(); + } + $this->lockingCache = $lockingCache; } @@ -45,26 +71,30 @@ public function index() { * @NoAdminRequired */ public function deleteActivitiesCustom() { - $sqlWhere = ' WHERE ' . " user='".$this->userId."'"; + if (!$this->lockingCache->hasKey($this->userId)) { + $this->lockingCache->set($this->userId, 'locked', 10); + $this->logger->debug('***********Lock applied for 10 seconds***************', ['app' => 'nmc_files_activity']); + $sqlWhere = ' WHERE ' . " user='".$this->userId."'"; - // Add galera safe delete chunking if using mysql - // Stops us hitting wsrep_max_ws_rows when large row counts are deleted - if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) { - // Then use chunked delete - $max = 100000; - $query = $this->connection->prepare( - 'DELETE FROM `*PREFIX*activity`' . $sqlWhere . " LIMIT " . $max); + // Add galera safe delete chunking if using mysql + // Stops us hitting wsrep_max_ws_rows when large row counts are deleted + if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) { + // Then use chunked delete + $max = 100000; + $query = $this->connection->prepare( + 'DELETE FROM `*PREFIX*activity`' . $sqlWhere . " LIMIT " . $max); - do { + do { + $query->execute(); + $deleted = $query->rowCount(); + } while ($deleted === $max); + } else { + // Dont use chunked delete - let the DB handle the large row count natively + $query = $this->connection->prepare( + 'DELETE FROM `*PREFIX*activity`' . $sqlWhere); $query->execute(); - $deleted = $query->rowCount(); - } while ($deleted === $max); - } else { - // Dont use chunked delete - let the DB handle the large row count natively - $query = $this->connection->prepare( - 'DELETE FROM `*PREFIX*activity`' . $sqlWhere); - $query->execute(); + } + $this->lockingCache->remove($this->userId); } } - }