Move get used optional file size to separate function

This commit is contained in:
shortcutme 2018-01-19 02:14:29 +01:00
parent a715650af6
commit d7b6c54b08
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -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)