225
225
from galaxy .util .sanitize_html import sanitize_html
226
226
227
227
if TYPE_CHECKING :
228
+ from sqlalchemy .sql .expression import BindParameter
229
+
230
+ from galaxy .objectstore import (
231
+ BaseObjectStore ,
232
+ QuotaSourceMap ,
233
+ )
228
234
from galaxy .schema .invocation import InvocationMessageUnion
229
235
230
236
log = logging .getLogger (__name__ )
@@ -652,9 +658,9 @@ def stderr(self, stderr):
652
658
"""
653
659
654
660
655
- def calculate_user_disk_usage_statements (user_id , quota_source_map , for_sqlite = False ):
661
+ def calculate_user_disk_usage_statements (user_id : int , quota_source_map : "QuotaSourceMap" , for_sqlite : bool = False ):
656
662
"""Standalone function so can be reused for postgres directly in pgcleanup.py."""
657
- statements = []
663
+ statements : List [ Tuple [ str , Dict [ str , Any ]]] = []
658
664
default_quota_enabled = quota_source_map .default_quota_enabled
659
665
default_exclude_ids = quota_source_map .default_usage_excluded_ids ()
660
666
default_cond = "dataset.object_store_id IS NULL" if default_quota_enabled and default_exclude_ids else ""
@@ -670,7 +676,7 @@ def calculate_user_disk_usage_statements(user_id, quota_source_map, for_sqlite=F
670
676
UPDATE galaxy_user SET disk_usage = ({ default_usage } )
671
677
WHERE id = :id
672
678
"""
673
- params = {"id" : user_id }
679
+ params : Dict [ str , Any ] = {"id" : user_id }
674
680
if default_exclude_ids :
675
681
params ["exclude_object_store_ids" ] = default_exclude_ids
676
682
statements .append ((default_usage , params ))
@@ -1147,25 +1153,27 @@ def calculate_disk_usage_default_source(self, object_store):
1147
1153
usage = sa_session .scalar (sql_calc , params )
1148
1154
return usage
1149
1155
1150
- def calculate_and_set_disk_usage (self , object_store ):
1156
+ def calculate_and_set_disk_usage (self , object_store : "BaseObjectStore" ):
1151
1157
"""
1152
1158
Calculates and sets user disk usage.
1153
1159
"""
1154
1160
self ._calculate_or_set_disk_usage (object_store = object_store )
1155
1161
1156
- def _calculate_or_set_disk_usage (self , object_store ):
1162
+ def _calculate_or_set_disk_usage (self , object_store : "BaseObjectStore" ):
1157
1163
"""
1158
1164
Utility to calculate and return the disk usage. If dryrun is False,
1159
1165
the new value is set immediately.
1160
1166
"""
1161
1167
assert object_store is not None
1162
1168
quota_source_map = object_store .get_quota_source_map ()
1163
1169
sa_session = object_session (self )
1170
+ assert sa_session
1171
+ assert sa_session .bind
1164
1172
for_sqlite = "sqlite" in sa_session .bind .dialect .name
1165
1173
statements = calculate_user_disk_usage_statements (self .id , quota_source_map , for_sqlite )
1166
1174
for sql , args in statements :
1167
1175
statement = text (sql )
1168
- binds = []
1176
+ binds : List [ BindParameter ] = []
1169
1177
for key , _ in args .items ():
1170
1178
expand_binding = key .endswith ("s" )
1171
1179
binds .append (bindparam (key , expanding = expand_binding ))
0 commit comments