From b33551e62e59ce4dd68110edcdd49330e3f4be17 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Mon, 15 Oct 2018 13:06:50 +0200 Subject: [PATCH] Exclude files larger than 20MB from garbage collection --- plugins/OptionalManager/ContentDbPlugin.py | 18 +++++++++++------- .../OptionalManager/OptionalManagerPlugin.py | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/OptionalManager/ContentDbPlugin.py b/plugins/OptionalManager/ContentDbPlugin.py index 255c0950..721ed8c4 100644 --- a/plugins/OptionalManager/ContentDbPlugin.py +++ b/plugins/OptionalManager/ContentDbPlugin.py @@ -285,9 +285,9 @@ class ContentDbPlugin(object): # First return the files with atleast 10 seeder and not accessed in last week query = """ 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 - """ % int(time.time() - 60 * 60 * 7) + """ % (self.getOptionalUsedWhere(), int(time.time() - 60 * 60 * 7)) limit_start = 0 while 1: num = 0 @@ -304,9 +304,9 @@ class ContentDbPlugin(object): # Then return files less seeder but still not accessed in last week query = """ 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 - """ % int(time.time() - 60 * 60 * 7) + """ % (self.getOptionalUsedWhere(), int(time.time() - 60 * 60 * 7)) limit_start = 0 while 1: num = 0 @@ -323,9 +323,9 @@ class ContentDbPlugin(object): # At the end return all files query = """ 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 - """ + """ % self.getOptionalUsedWhere() limit_start = 0 while 1: num = 0 @@ -345,8 +345,12 @@ class ContentDbPlugin(object): limit_bytes = float(re.sub("[^0-9.]", "", config.optional_limit)) * 1024 * 1024 * 1024 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): - 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: size = 0 return size diff --git a/plugins/OptionalManager/OptionalManagerPlugin.py b/plugins/OptionalManager/OptionalManagerPlugin.py index ff62058b..70c62446 100644 --- a/plugins/OptionalManager/OptionalManagerPlugin.py +++ b/plugins/OptionalManager/OptionalManagerPlugin.py @@ -167,5 +167,6 @@ class ConfigPlugin(object): 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('--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()