diff --git a/plugins/OptionalManager/ContentDbPlugin.py b/plugins/OptionalManager/ContentDbPlugin.py index 961a7390..f03ed4bb 100644 --- a/plugins/OptionalManager/ContentDbPlugin.py +++ b/plugins/OptionalManager/ContentDbPlugin.py @@ -343,6 +343,12 @@ class ContentDbPlugin(object): limit_bytes = float(re.sub("[^0-9.]", "", config.optional_limit)) * 1024 * 1024 * 1024 return limit_bytes + def getOptionalUsedBytes(self): + size = self.execute("SELECT SUM(size) FROM file_optional WHERE is_downloaded = 1 AND is_pinned = 0").fetchone()[0] + if not size: + size = 0 + return size + def getOptionalNeedDelete(self, size): if config.optional_limit.endswith("%"): limit_percent = float(re.sub("[^0-9.]", "", config.optional_limit)) @@ -359,9 +365,7 @@ class ContentDbPlugin(object): self.log.debug("Invalid limit for optional files: %s" % limit) return False - size = self.execute("SELECT SUM(size) FROM file_optional WHERE is_downloaded = 1 AND is_pinned = 0").fetchone()[0] - if not size: - size = 0 + size = self.getOptionalUsedBytes() need_delete = self.getOptionalNeedDelete(size)