mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-19 02:21:32 +08:00
Optimize getting current user session
We get all user session when logging in, this isn't necessary and does show up in a memray trace. I don't think it's a leak, but this is going to be more efficient.
This commit is contained in:
@@ -10736,6 +10736,20 @@ WorkflowInvocationStep.subworkflow_invocation_id = column_property(
|
||||
# <user_obj>.preferences[pref_name] = pref_value
|
||||
User.preferences = association_proxy("_preferences", "value", creator=UserPreference)
|
||||
|
||||
# Optimized version of getting the current Galaxy session.
|
||||
# See https://github.com/sqlalchemy/sqlalchemy/discussions/7638 for approach
|
||||
session_partition = select(
|
||||
GalaxySession,
|
||||
func.row_number().over(order_by=GalaxySession.update_time, partition_by=GalaxySession.user_id).label("index"),
|
||||
).alias()
|
||||
partitioned_session = aliased(GalaxySession, session_partition)
|
||||
User.current_galaxy_session = relationship(
|
||||
partitioned_session,
|
||||
primaryjoin=and_(partitioned_session.user_id == User.id, session_partition.c.index < 2),
|
||||
uselist=False,
|
||||
viewonly=True,
|
||||
)
|
||||
|
||||
|
||||
@event.listens_for(HistoryDatasetCollectionAssociation, "init")
|
||||
def receive_init(target, args, kwargs):
|
||||
|
||||
@@ -835,7 +835,7 @@ class GalaxyWebTransaction(base.DefaultWebTransaction, context.ProvidesHistoryCo
|
||||
history = None
|
||||
set_permissions = False
|
||||
try:
|
||||
users_last_session = user.galaxy_sessions[0]
|
||||
users_last_session = user.current_galaxy_session
|
||||
except Exception:
|
||||
users_last_session = None
|
||||
if (
|
||||
|
||||
@@ -77,7 +77,7 @@ class UserListGrid(grids.Grid):
|
||||
class LastLoginColumn(grids.GridColumn):
|
||||
def get_value(self, trans, grid, user):
|
||||
if user.galaxy_sessions:
|
||||
return self.format(user.galaxy_sessions[0].update_time)
|
||||
return self.format(user.current_galaxy_session.update_time)
|
||||
return "never"
|
||||
|
||||
def sort(self, trans, query, ascending, column_name=None):
|
||||
|
||||
@@ -164,8 +164,9 @@ class Users(BaseUIController, ReportQueryBuilder):
|
||||
.filter(galaxy.model.User.table.c.deleted == false())
|
||||
.order_by(galaxy.model.User.table.c.email)
|
||||
):
|
||||
if user.galaxy_sessions:
|
||||
last_galaxy_session = user.galaxy_sessions[0]
|
||||
current_galaxy_session = user.current_galaxy_session
|
||||
if current_galaxy_session:
|
||||
last_galaxy_session = current_galaxy_session
|
||||
if last_galaxy_session.update_time < cutoff_time:
|
||||
users.append((user.email, last_galaxy_session.update_time.strftime("%Y-%m-%d")))
|
||||
else:
|
||||
|
||||
@@ -46,8 +46,8 @@ class UserGrid(grids.Grid):
|
||||
|
||||
class LastLoginColumn(grids.GridColumn):
|
||||
def get_value(self, trans, grid, user):
|
||||
if user.galaxy_sessions:
|
||||
return self.format(user.galaxy_sessions[0].update_time)
|
||||
if user.current_galaxy_session:
|
||||
return self.format(user.current_galaxy_session.update_time)
|
||||
return "never"
|
||||
|
||||
class StatusColumn(grids.GridColumn):
|
||||
|
||||
Reference in New Issue
Block a user