Browse Source

Use less db.commits when adding quality and profiles.

pull/918/head
Ruud 13 years ago
parent
commit
f3e3632dd3
  1. 4
      couchpotato/core/plugins/profile/main.py
  2. 41
      couchpotato/core/plugins/quality/main.py

4
couchpotato/core/plugins/profile/main.py

@ -181,10 +181,10 @@ class ProfilePlugin(Plugin):
) )
p.types.append(profile_type) p.types.append(profile_type)
db.commit()
quality_order += 1 quality_order += 1
order += 1 order += 1
#db.close() db.commit()
return True return True

41
couchpotato/core/plugins/quality/main.py

@ -9,6 +9,7 @@ from couchpotato.core.plugins.base import Plugin
from couchpotato.core.settings.model import Quality, Profile, ProfileType from couchpotato.core.settings.model import Quality, Profile, ProfileType
import os.path import os.path
import re import re
import time
log = CPLog(__name__) log = CPLog(__name__)
@ -113,46 +114,48 @@ class QualityPlugin(Plugin):
for q in self.qualities: for q in self.qualities:
# Create quality # Create quality
quality = db.query(Quality).filter_by(identifier = q.get('identifier')).first() qual = db.query(Quality).filter_by(identifier = q.get('identifier')).first()
if not quality: if not qual:
log.info('Creating quality: %s', q.get('label')) log.info('Creating quality: %s', q.get('label'))
quality = Quality() qual = Quality()
db.add(quality) qual.order = order
qual.identifier = q.get('identifier')
qual.label = toUnicode(q.get('label'))
qual.size_min, qual.size_max = q.get('size')
quality.order = order db.add(qual)
quality.identifier = q.get('identifier')
quality.label = toUnicode(q.get('label'))
quality.size_min, quality.size_max = q.get('size')
# Create single quality profile # Create single quality profile
profile = db.query(Profile).filter( prof = db.query(Profile).filter(
Profile.core == True Profile.core == True
).filter( ).filter(
Profile.types.any(quality = quality) Profile.types.any(quality = qual)
).all() ).all()
if not profile: if not prof:
log.info('Creating profile: %s', q.get('label')) log.info('Creating profile: %s', q.get('label'))
profile = Profile( prof = Profile(
core = True, core = True,
label = toUnicode(quality.label), label = toUnicode(qual.label),
order = order order = order
) )
db.add(profile) db.add(prof)
profile_type = ProfileType( profile_type = ProfileType(
quality = quality, quality = qual,
profile = profile, profile = prof,
finish = True, finish = True,
order = 0 order = 0
) )
profile.types.append(profile_type) prof.types.append(profile_type)
order += 1 order += 1
db.commit()
#db.close() db.commit()
time.sleep(0.3) # Wait a moment
return True return True
def guess(self, files, extra = {}): def guess(self, files, extra = {}):

Loading…
Cancel
Save