Skip to content

Commit

Permalink
Merge pull request #1 from nextmcloud/nmcfix/451-activities-delete-bu…
Browse files Browse the repository at this point in the history
…tton

Nmcfix/451 activities delete button
  • Loading branch information
TSI-sangramdesai authored Feb 18, 2022
2 parents a333521 + 110e24d commit 2cb8f3e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
16 changes: 13 additions & 3 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});

});
};

Expand All @@ -20,7 +30,7 @@
}
})();

nmcFilesActvityAction.delActvities();
nmcFilesActvityAction.delActvities();
});


Expand Down
66 changes: 48 additions & 18 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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);
}
}

}

0 comments on commit 2cb8f3e

Please sign in to comment.