230
230
from galaxy .util .sanitize_html import sanitize_html
231
231
232
232
if TYPE_CHECKING :
233
+ from sqlalchemy .sql .expression import BindParameter
234
+
233
235
from galaxy .objectstore import (
234
236
BaseObjectStore ,
235
237
ObjectStorePopulator ,
238
+ QuotaSourceMap ,
236
239
)
237
240
from galaxy .schema .invocation import InvocationMessageUnion
238
241
@@ -674,9 +677,9 @@ def stderr(self, stderr):
674
677
"""
675
678
676
679
677
- def calculate_user_disk_usage_statements (user_id , quota_source_map , for_sqlite = False ):
680
+ def calculate_user_disk_usage_statements (user_id : int , quota_source_map : "QuotaSourceMap" , for_sqlite : bool = False ):
678
681
"""Standalone function so can be reused for postgres directly in pgcleanup.py."""
679
- statements = []
682
+ statements : List [ Tuple [ str , Dict [ str , Any ]]] = []
680
683
default_quota_enabled = quota_source_map .default_quota_enabled
681
684
default_exclude_ids = quota_source_map .default_usage_excluded_ids ()
682
685
default_cond = "dataset.object_store_id IS NULL" if default_quota_enabled and default_exclude_ids else ""
@@ -692,7 +695,7 @@ def calculate_user_disk_usage_statements(user_id, quota_source_map, for_sqlite=F
692
695
UPDATE galaxy_user SET disk_usage = ({ default_usage } )
693
696
WHERE id = :id
694
697
"""
695
- params = {"id" : user_id }
698
+ params : Dict [ str , Any ] = {"id" : user_id }
696
699
if default_exclude_ids :
697
700
params ["exclude_object_store_ids" ] = default_exclude_ids
698
701
statements .append ((default_usage , params ))
@@ -1161,25 +1164,27 @@ def calculate_disk_usage_default_source(self, object_store):
1161
1164
usage = sa_session .scalar (sql_calc , params )
1162
1165
return usage
1163
1166
1164
- def calculate_and_set_disk_usage (self , object_store ):
1167
+ def calculate_and_set_disk_usage (self , object_store : "BaseObjectStore" ):
1165
1168
"""
1166
1169
Calculates and sets user disk usage.
1167
1170
"""
1168
1171
self ._calculate_or_set_disk_usage (object_store = object_store )
1169
1172
1170
- def _calculate_or_set_disk_usage (self , object_store ):
1173
+ def _calculate_or_set_disk_usage (self , object_store : "BaseObjectStore" ):
1171
1174
"""
1172
1175
Utility to calculate and return the disk usage. If dryrun is False,
1173
1176
the new value is set immediately.
1174
1177
"""
1175
1178
assert object_store is not None
1176
1179
quota_source_map = object_store .get_quota_source_map ()
1177
1180
sa_session = object_session (self )
1181
+ assert sa_session
1182
+ assert sa_session .bind
1178
1183
for_sqlite = "sqlite" in sa_session .bind .dialect .name
1179
1184
statements = calculate_user_disk_usage_statements (self .id , quota_source_map , for_sqlite )
1180
1185
for sql , args in statements :
1181
1186
statement = text (sql )
1182
- binds = []
1187
+ binds : List [ BindParameter ] = []
1183
1188
for key , _ in args .items ():
1184
1189
expand_binding = key .endswith ("s" )
1185
1190
binds .append (bindparam (key , expanding = expand_binding ))
0 commit comments