Re-use session. fix #252

This commit is contained in:
Ruud
2012-05-11 23:17:50 +02:00
parent 4bdd23e36a
commit 921a851b7e
17 changed files with 48 additions and 48 deletions
+4 -4
View File
@@ -65,7 +65,7 @@ class CoreNotifier(Notification):
q.update({Notif.read: True})
db.commit()
db.close()
#db.close()
return jsonified({
'success': True
@@ -91,7 +91,7 @@ class CoreNotifier(Notification):
ndict['type'] = 'notification'
notifications.append(ndict)
db.close()
#db.close()
return jsonified({
'success': True,
'empty': len(notifications) == 0,
@@ -116,7 +116,7 @@ class CoreNotifier(Notification):
ndict['time'] = time.time()
self.messages.append(ndict)
db.close()
#db.close()
return True
def frontend(self, type = 'notification', data = {}):
@@ -146,7 +146,7 @@ class CoreNotifier(Notification):
ndict['type'] = 'notification'
messages.append(ndict)
db.close()
#db.close()
self.messages = []
return jsonified({
@@ -22,6 +22,6 @@ class History(Notification):
)
db.add(history)
db.commit()
db.close()
#db.close()
return True
+2 -2
View File
@@ -87,7 +87,7 @@ class FileManager(Plugin):
db.commit()
type_dict = ft.to_dict()
db.close()
#db.close()
return type_dict
def getTypes(self):
@@ -100,5 +100,5 @@ class FileManager(Plugin):
for type_object in results:
types.append(type_object.to_dict())
db.close()
#db.close()
return types
+3 -3
View File
@@ -53,7 +53,7 @@ class LibraryPlugin(Plugin):
library_dict = l.to_dict(self.default_dict)
db.close()
#db.close()
return library_dict
def update(self, identifier, default_title = '', force = False):
@@ -130,7 +130,7 @@ class LibraryPlugin(Plugin):
fireEvent('library.update_finish', data = library_dict)
db.close()
#db.close()
return library_dict
def updateReleaseDate(self, identifier):
@@ -144,7 +144,7 @@ class LibraryPlugin(Plugin):
db.commit()
dates = library.info.get('release_date', {})
db.close()
#db.close()
return dates
+8 -8
View File
@@ -113,7 +113,7 @@ class MoviePlugin(Plugin):
if m:
results = m.to_dict(self.default_dict)
db.close()
#db.close()
return results
def list(self, status = ['active'], limit_offset = None, starts_with = None, search = None):
@@ -177,7 +177,7 @@ class MoviePlugin(Plugin):
})
movies.append(temp)
db.close()
#db.close()
return movies
def availableChars(self, status = ['active']):
@@ -203,7 +203,7 @@ class MoviePlugin(Plugin):
if char not in chars:
chars += char
db.close()
#db.close()
return chars
def listView(self):
@@ -250,7 +250,7 @@ class MoviePlugin(Plugin):
fireEventAsync('library.update', identifier = movie.library.identifier, default_title = default_title, force = True)
fireEventAsync('searcher.single', movie.to_dict(self.default_dict))
db.close()
#db.close()
return jsonified({
'success': True,
})
@@ -324,7 +324,7 @@ class MoviePlugin(Plugin):
if (force_readd or do_search) and search_after:
fireEventAsync('searcher.single', movie_dict)
db.close()
#db.close()
return movie_dict
@@ -371,7 +371,7 @@ class MoviePlugin(Plugin):
movie_dict = m.to_dict(self.default_dict)
fireEventAsync('searcher.single', movie_dict)
db.close()
#db.close()
return jsonified({
'success': True,
})
@@ -426,7 +426,7 @@ class MoviePlugin(Plugin):
else:
fireEvent('movie.restatus', movie.id, single = True)
db.close()
#db.close()
return True
def restatus(self, movie_id):
@@ -455,6 +455,6 @@ class MoviePlugin(Plugin):
m.status_id = active_status.get('id') if move_to_wanted else done_status.get('id')
db.commit()
db.close()
#db.close()
return True
+6 -6
View File
@@ -47,7 +47,7 @@ class ProfilePlugin(Plugin):
for profile in profiles:
temp.append(profile.to_dict(self.to_dict))
db.close()
#db.close()
return temp
def save(self):
@@ -84,7 +84,7 @@ class ProfilePlugin(Plugin):
profile_dict = p.to_dict(self.to_dict)
db.close()
#db.close()
return jsonified({
'success': True,
'profile': profile_dict
@@ -95,7 +95,7 @@ class ProfilePlugin(Plugin):
db = get_session()
default = db.query(Profile).first()
default_dict = default.to_dict(self.to_dict)
db.close()
#db.close()
return default_dict
@@ -113,7 +113,7 @@ class ProfilePlugin(Plugin):
order += 1
db.commit()
db.close()
#db.close()
return jsonified({
'success': True
@@ -138,7 +138,7 @@ class ProfilePlugin(Plugin):
message = 'Failed deleting Profile: %s' % e
log.error(message)
db.close()
#db.close()
return jsonified({
'success': success,
@@ -187,5 +187,5 @@ class ProfilePlugin(Plugin):
order += 1
db.close()
#db.close()
return True
+4 -4
View File
@@ -68,7 +68,7 @@ class QualityPlugin(Plugin):
q = mergeDicts(self.getQuality(quality.identifier), quality.to_dict())
temp.append(q)
db.close()
#db.close()
return temp
def single(self, identifier = ''):
@@ -80,7 +80,7 @@ class QualityPlugin(Plugin):
if quality:
quality_dict = dict(self.getQuality(quality.identifier), **quality.to_dict())
db.close()
#db.close()
return quality_dict
def getQuality(self, identifier):
@@ -100,7 +100,7 @@ class QualityPlugin(Plugin):
setattr(quality, params.get('value_type'), params.get('value'))
db.commit()
db.close()
#db.close()
return jsonified({
'success': True
})
@@ -152,7 +152,7 @@ class QualityPlugin(Plugin):
order += 1
db.commit()
db.close()
#db.close()
return True
def guess(self, files, extra = {}):
+5 -5
View File
@@ -83,7 +83,7 @@ class Release(Plugin):
fireEvent('movie.restatus', movie.id)
db.close()
#db.close()
return True
@@ -109,7 +109,7 @@ class Release(Plugin):
rel.delete()
db.commit()
db.close()
#db.close()
return jsonified({
'success': True
})
@@ -126,7 +126,7 @@ class Release(Plugin):
rel.status_id = available_status.get('id') if rel.status_id is ignored_status.get('id') else ignored_status.get('id')
db.commit()
db.close()
#db.close()
return jsonified({
'success': True
})
@@ -153,14 +153,14 @@ class Release(Plugin):
'files': {}
}), manual = True)
db.close()
#db.close()
return jsonified({
'success': True
})
else:
log.error('Couldn\'t find release with id: %s' % id)
db.close()
#db.close()
return jsonified({
'success': False
})
+1 -1
View File
@@ -378,7 +378,7 @@ class Renamer(Plugin):
if self.shuttingDown():
break
db.close()
#db.close()
self.renaming_started = False
def getRenameExtras(self, extra_type = '', replacements = {}, folder_name = '', file_name = '', destination = '', group = {}, current_file = ''):
+1 -1
View File
@@ -455,7 +455,7 @@ class Scanner(Plugin):
break
except:
pass
db.close()
#db.close()
# Search based on OpenSubtitleHash
if not imdb_id and not group['is_dvd']:
+3 -3
View File
@@ -61,7 +61,7 @@ class Searcher(Plugin):
if self.shuttingDown():
break
db.close()
#db.close()
self.in_progress = False
def single(self, movie):
@@ -155,7 +155,7 @@ class Searcher(Plugin):
if self.shuttingDown():
break
db.close()
#db.close()
return False
def download(self, data, movie, manual = False):
@@ -198,7 +198,7 @@ class Searcher(Plugin):
except Exception, e:
log.error('Failed marking movie finished: %s %s' % (e, traceback.format_exc()))
db.close()
#db.close()
return True
log.info('Tried to download, but none of the downloaders are enabled')
+4 -4
View File
@@ -49,7 +49,7 @@ class StatusPlugin(Plugin):
db = get_session()
status = db.query(Status).filter_by(id = id).first()
status_dict = status.to_dict()
db.close()
#db.close()
return status_dict
@@ -64,7 +64,7 @@ class StatusPlugin(Plugin):
s = status.to_dict()
temp.append(s)
db.close()
#db.close()
return temp
def add(self, identifier):
@@ -82,7 +82,7 @@ class StatusPlugin(Plugin):
status_dict = s.to_dict()
db.close()
#db.close()
return status_dict
def fill(self):
@@ -102,5 +102,5 @@ class StatusPlugin(Plugin):
s.label = toUnicode(label)
db.commit()
db.close()
#db.close()
+1 -1
View File
@@ -38,7 +38,7 @@ class Subtitle(Plugin):
# get subtitles for those files
subliminal.list_subtitles(files, cache_dir = Env.get('cache_dir'), multi = True, languages = self.getLanguages(), services = self.services)
db.close()
#db.close()
def searchSingle(self, group):
@@ -63,7 +63,7 @@ class MovieResultModifier(Plugin):
except:
log.error('Tried getting more info on searched movies: %s' % traceback.format_exc())
db.close()
#db.close()
return temp
def checkLibrary(self, result):
@@ -59,7 +59,7 @@ class CouchPotatoApi(MovieProvider):
db = get_session()
active_movies = db.query(Movie).filter(Movie.status.has(identifier = 'active')).all()
movies = [x.library.identifier for x in active_movies]
db.close()
#db.close()
suggestions = self.suggest(movies, ignore)
+2 -2
View File
@@ -204,7 +204,7 @@ class Settings(object):
except:
pass
db.close()
#db.close()
return prop
def setProperty(self, identifier, value = ''):
@@ -221,4 +221,4 @@ class Settings(object):
p.value = toUnicode(value)
db.commit()
db.close()
#db.close()
+1 -1
View File
@@ -65,7 +65,7 @@ class Env(object):
@staticmethod
def getEngine():
return create_engine(Env.get('db_path'), echo = False)
return create_engine(Env.get('db_path'), echo = False, pool_recycle = 30)
@staticmethod
def setting(attr, section = 'core', value = None, default = '', type = None):