Exclude files larger than 20MB from garbage collection

This commit is contained in:
shortcutme 2018-10-15 13:06:50 +02:00
parent 8bb4d149b6
commit b33551e62e
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
2 changed files with 12 additions and 7 deletions

View file

@ -285,9 +285,9 @@ class ContentDbPlugin(object):
# First return the files with atleast 10 seeder and not accessed in last week # First return the files with atleast 10 seeder and not accessed in last week
query = """ query = """
SELECT * FROM file_optional SELECT * FROM file_optional
WHERE peer > 10 AND is_downloaded = 1 AND is_pinned = 0 WHERE peer > 10 AND %s
ORDER BY time_accessed < %s DESC, uploaded / size ORDER BY time_accessed < %s DESC, uploaded / size
""" % int(time.time() - 60 * 60 * 7) """ % (self.getOptionalUsedWhere(), int(time.time() - 60 * 60 * 7))
limit_start = 0 limit_start = 0
while 1: while 1:
num = 0 num = 0
@ -304,9 +304,9 @@ class ContentDbPlugin(object):
# Then return files less seeder but still not accessed in last week # Then return files less seeder but still not accessed in last week
query = """ query = """
SELECT * FROM file_optional SELECT * FROM file_optional
WHERE is_downloaded = 1 AND peer <= 10 AND is_pinned = 0 WHERE peer <= 10 AND %s
ORDER BY peer DESC, time_accessed < %s DESC, uploaded / size ORDER BY peer DESC, time_accessed < %s DESC, uploaded / size
""" % int(time.time() - 60 * 60 * 7) """ % (self.getOptionalUsedWhere(), int(time.time() - 60 * 60 * 7))
limit_start = 0 limit_start = 0
while 1: while 1:
num = 0 num = 0
@ -323,9 +323,9 @@ class ContentDbPlugin(object):
# At the end return all files # At the end return all files
query = """ query = """
SELECT * FROM file_optional SELECT * FROM file_optional
WHERE is_downloaded = 1 AND peer <= 10 AND is_pinned = 0 WHERE peer <= 10 AND %s
ORDER BY peer DESC, time_accessed, uploaded / size ORDER BY peer DESC, time_accessed, uploaded / size
""" """ % self.getOptionalUsedWhere()
limit_start = 0 limit_start = 0
while 1: while 1:
num = 0 num = 0
@ -345,8 +345,12 @@ class ContentDbPlugin(object):
limit_bytes = float(re.sub("[^0-9.]", "", config.optional_limit)) * 1024 * 1024 * 1024 limit_bytes = float(re.sub("[^0-9.]", "", config.optional_limit)) * 1024 * 1024 * 1024
return limit_bytes return limit_bytes
def getOptionalUsedWhere(self):
maxsize = config.optional_limit_exclude_minsize * 1024 * 1024
return "is_downloaded = 1 AND is_pinned = 0 AND size < %s" % maxsize
def getOptionalUsedBytes(self): def getOptionalUsedBytes(self):
size = self.execute("SELECT SUM(size) FROM file_optional WHERE is_downloaded = 1 AND is_pinned = 0").fetchone()[0] size = self.execute("SELECT SUM(size) FROM file_optional WHERE %s" % self.getOptionalUsedWhere()).fetchone()[0]
if not size: if not size:
size = 0 size = 0
return size return size

View file

@ -167,5 +167,6 @@ class ConfigPlugin(object):
group = self.parser.add_argument_group("OptionalManager plugin") group = self.parser.add_argument_group("OptionalManager plugin")
group.add_argument('--optional_limit', help='Limit total size of optional files', default="10%", metavar="GB or free space %") group.add_argument('--optional_limit', help='Limit total size of optional files', default="10%", metavar="GB or free space %")
group.add_argument('--pin_bigfile', help='Automatically pin files larger than this limit', default=20, metavar="MB", type=int) group.add_argument('--pin_bigfile', help='Automatically pin files larger than this limit', default=20, metavar="MB", type=int)
group.add_argument('--optional_limit_exclude_minsize', help='Exclude files larger than this limit from optional size limit calculation', default=20, metavar="MB", type=int)
return super(ConfigPlugin, self).createArguments() return super(ConfigPlugin, self).createArguments()