diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-27 20:15:35 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-27 20:22:01 +0100 |
commit | 82159d488d87d204390dc58fdd30ca2167156b79 (patch) | |
tree | 18890ad530f1b0bcc0a4b4d6f983c06a21280be9 /app/models.py | |
parent | 5e4613a6ef78180f208b0cd58aeffb63f1e19853 (diff) | |
download | cheatdb-82159d488d87d204390dc58fdd30ca2167156b79.tar.xz |
Add meta package selector
Diffstat (limited to 'app/models.py')
-rw-r--r-- | app/models.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/app/models.py b/app/models.py index ea8bb18..bfd8a31 100644 --- a/app/models.py +++ b/app/models.py @@ -415,6 +415,19 @@ class MetaPackage(db.Model): return ",".join([str(x) for x in list]) @staticmethod + def GetOrCreate(name, cache={}): + mp = cache.get(name) + if mp is None: + mp = MetaPackage.query.filter_by(name=name).first() + + if mp is None: + mp = MetaPackage(name) + db.session.add(mp) + + cache[name] = mp + return mp + + @staticmethod def SpecToList(spec, cache={}): retval = [] arr = spec.split(",") @@ -430,16 +443,7 @@ class MetaPackage(db.Model): if not pattern.match(x): continue - mp = cache.get(x) - if mp is None: - mp = MetaPackage.query.filter_by(name=x).first() - - if mp is None: - mp = MetaPackage(x) - db.session.add(mp) - - cache[x] = mp - retval.append(mp) + retval.append(MetaPackage.GetOrCreate(x, cache)) return retval |