From 7818b430456d05e857c8a361314662253133c3f4 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 27 Apr 2013 10:08:03 +0200 Subject: [PATCH] Release files add in bulk --- couchpotato/core/plugins/release/main.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/plugins/release/main.py b/couchpotato/core/plugins/release/main.py index 68bf60a6..5c4d39f2 100644 --- a/couchpotato/core/plugins/release/main.py +++ b/couchpotato/core/plugins/release/main.py @@ -41,6 +41,7 @@ class Release(Plugin): addEvent('release.clean', self.clean) def add(self, group): + db = get_session() identifier = '%s.%s.%s' % (group['library']['identifier'], group['meta_data'].get('audio', 'unknown'), group['meta_data']['quality']['identifier']) @@ -76,15 +77,19 @@ class Release(Plugin): db.commit() # Add each file type + added_files = [] for type in group['files']: for cur_file in group['files'][type]: added_file = self.saveFile(cur_file, type = type, include_media_info = type is 'movie') - try: - added_file = db.query(File).filter_by(id = added_file.get('id')).one() - rel.files.append(added_file) - db.commit() - except Exception, e: - log.debug('Failed to attach "%s" to release: %s', (cur_file, e)) + added_files.append(added_file.get('id')) + + # Add the release files in batch + try: + added_files = db.query(File).filter(or_(*[File.id == x for x in added_files])).all() + rel.files.append(added_files) + db.commit() + except Exception, e: + log.debug('Failed to attach "%s" to release: %s', (cur_file, e)) fireEvent('movie.restatus', movie.id)