aboutsummaryrefslogtreecommitdiff
path: root/app/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/models.py')
-rw-r--r--app/models.py24
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