diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2016-02-04 18:34:01 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-02-05 15:36:21 +0100 |
commit | d537cae06345af37857b20a1a315229881e1c6c7 (patch) | |
tree | d3aea0856d58a85b0e21ec15cf9d8d5e43337597 /apps/files/lib | |
parent | e15a120f83f9eaf910db12b7c478330623a71e72 (diff) | |
download | nextcloud-server-d537cae06345af37857b20a1a315229881e1c6c7.tar.gz nextcloud-server-d537cae06345af37857b20a1a315229881e1c6c7.zip |
cleanup jobs for comments and comment read marks
Diffstat (limited to 'apps/files/lib')
-rw-r--r-- | apps/files/lib/backgroundjob/deleteorphaneditems.php (renamed from apps/files/lib/backgroundjob/deleteorphanedtagsjob.php) | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/apps/files/lib/backgroundjob/deleteorphanedtagsjob.php b/apps/files/lib/backgroundjob/deleteorphaneditems.php index 33f455b5b40..37c05ce214f 100644 --- a/apps/files/lib/backgroundjob/deleteorphanedtagsjob.php +++ b/apps/files/lib/backgroundjob/deleteorphaneditems.php @@ -26,7 +26,7 @@ use OC\BackgroundJob\TimedJob; /** * Delete all share entries that have no matching entries in the file cache table. */ -class DeleteOrphanedTagsJob extends TimedJob { +class DeleteOrphanedItems extends TimedJob { /** @var \OCP\IDBConnection */ protected $connection; @@ -58,6 +58,8 @@ class DeleteOrphanedTagsJob extends TimedJob { public function run($argument) { $this->cleanSystemTags(); $this->cleanUserTags(); + $this->cleanComments(); + $this->cleanCommentMarkers(); } /** @@ -65,19 +67,29 @@ class DeleteOrphanedTagsJob extends TimedJob { * * @return int Number of deleted entries */ - protected function cleanSystemTags() { + protected function cleanUp($table, $idCol, $typeCol) { $subQuery = $this->connection->getQueryBuilder(); $subQuery->select($subQuery->expr()->literal('1')) ->from('filecache', 'f') - ->where($subQuery->expr()->eq('objectid', 'f.fileid')); + ->where($subQuery->expr()->eq($idCol, 'f.fileid')); $query = $this->connection->getQueryBuilder(); - $deletedEntries = $query->delete('systemtag_object_mapping') - ->where($query->expr()->eq('objecttype', $query->expr()->literal('files'))) + $deletedEntries = $query->delete($table) + ->where($query->expr()->eq($typeCol, $query->expr()->literal('files'))) ->andWhere($query->expr()->isNull($query->createFunction('(' . $subQuery->getSql() . ')'))) ->execute(); - $this->logger->debug("$deletedEntries orphaned system tag relations deleted", ['app' => 'DeleteOrphanedTagsJob']); + return $deletedEntries; + } + + /** + * Deleting orphaned system tag mappings + * + * @return int Number of deleted entries + */ + protected function cleanSystemTags() { + $deletedEntries = $this->cleanUp('systemtag_object_mapping', 'objectid', 'objecttype'); + $this->logger->debug("$deletedEntries orphaned system tag relations deleted", ['app' => 'DeleteOrphanedItems']); return $deletedEntries; } @@ -87,18 +99,30 @@ class DeleteOrphanedTagsJob extends TimedJob { * @return int Number of deleted entries */ protected function cleanUserTags() { - $subQuery = $this->connection->getQueryBuilder(); - $subQuery->select($subQuery->expr()->literal('1')) - ->from('filecache', 'f') - ->where($subQuery->expr()->eq('objid', 'f.fileid')); + $deletedEntries = $this->cleanUp('vcategory_to_object', 'objid', 'type'); + $this->logger->debug("$deletedEntries orphaned user tag relations deleted", ['app' => 'DeleteOrphanedItems']); + return $deletedEntries; + } - $query = $this->connection->getQueryBuilder(); - $deletedEntries = $query->delete('vcategory_to_object') - ->where($query->expr()->eq('type', $query->expr()->literal('files'))) - ->andWhere($query->expr()->isNull($query->createFunction('(' . $subQuery->getSql() . ')'))) - ->execute(); + /** + * Deleting orphaned comments + * + * @return int Number of deleted entries + */ + protected function cleanComments() { + $deletedEntries = $this->cleanUp('comments', 'object_id', 'object_type'); + $this->logger->debug("$deletedEntries orphaned comments deleted", ['app' => 'DeleteOrphanedItems']); + return $deletedEntries; + } - $this->logger->debug("$deletedEntries orphaned user tag relations deleted", ['app' => 'DeleteOrphanedTagsJob']); + /** + * Deleting orphaned comment read markers + * + * @return int Number of deleted entries + */ + protected function cleanCommentMarkers() { + $deletedEntries = $this->cleanUp('comments_read_markers', 'object_id', 'object_type'); + $this->logger->debug("$deletedEntries orphaned comment read marks deleted", ['app' => 'DeleteOrphanedItems']); return $deletedEntries; } |