Skip to content

Commit

Permalink
Move the user calculate_and_set_disk_usage functionality to the model…
Browse files Browse the repository at this point in the history
… instead of the queue worker.
  • Loading branch information
dannon committed Mar 9, 2017
1 parent bcc4e02 commit 33ababa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 14 additions & 0 deletions lib/galaxy/model/__init__.py
Expand Up @@ -28,6 +28,7 @@
import galaxy.security.passwords
import galaxy.util
from galaxy.model.item_attrs import UsesAnnotations
from galaxy.model.util import pgcalc
from galaxy.security import get_permitted_actions
from galaxy.util import (directory_hash_id, Params, ready_name_for_url,
restore_text, send_mail, unicodify, unique_id)
Expand Down Expand Up @@ -275,6 +276,19 @@ def calculate_disk_usage( self ):
total += hda.dataset.get_total_size()
return total

def calculate_and_set_disk_usage( self ):
"""
Calculates and sets user disk usage.
"""
db_session = object_session(self)
if db_session.get_bind().dialect.name not in ( 'postgres', 'postgresql' ):
new = self.calculate_disk_usage()
else:
new = pgcalc(db_session, self.id)
self.set_disk_usage(new)
db_session.add(self)
db_session.flush()

@staticmethod
def user_template_environment( user ):
"""
Expand Down
10 changes: 1 addition & 9 deletions lib/galaxy/queue_worker.py
Expand Up @@ -9,7 +9,6 @@

import galaxy.queues
from galaxy import util
from galaxy.model.util import pgcalc

from kombu import Connection
from kombu.mixins import ConsumerMixin
Expand Down Expand Up @@ -142,14 +141,7 @@ def recalculate_user_disk_usage(app, **kwargs):
sa_session = app.model.context
if user_id:
user = sa_session.query( app.model.User ).get( app.security.decode_id( user_id ) )
if user:
if sa_session.get_bind().dialect.name not in ( 'postgres', 'postgresql' ):
new = user.calculate_disk_usage()
else:
new = pgcalc(sa_session, user.id)
user.set_disk_usage(new)
sa_session.add(user)
sa_session.flush()
user.calculate_and_set_disk_usage()


def reload_tool_data_tables(app, **kwargs):
Expand Down

0 comments on commit 33ababa

Please sign in to comment.