@@ -172,13 +172,9 @@ def get_expired_environments(self, current_ts: int) -> t.List[EnvironmentSummary
172172 Returns:
173173 The list of environment summaries to remove.
174174 """
175-
176- environment_summaries = self .get_environments_summary ()
177- return [
178- env_summary
179- for env_summary in environment_summaries
180- if env_summary .expiration_ts is not None and env_summary .expiration_ts <= current_ts
181- ]
175+ return self ._fetch_environment_summaries (
176+ where = self ._create_expiration_filter_expr (current_ts )
177+ )
182178
183179 def delete_expired_environments (
184180 self , current_ts : t .Optional [int ] = None
@@ -225,13 +221,7 @@ def get_environments_summary(self) -> t.List[EnvironmentSummary]:
225221 Returns:
226222 A list of all environment summaries.
227223 """
228- return [
229- self ._environment_summmary_from_row (row )
230- for row in fetchall (
231- self .engine_adapter ,
232- self ._environments_query (required_fields = list (EnvironmentSummary .all_fields ())),
233- )
234- ]
224+ return self ._fetch_environment_summaries ()
235225
236226 def get_environment (
237227 self , environment : str , lock_for_update : bool = False
@@ -327,6 +317,20 @@ def _create_expiration_filter_expr(self, current_ts: int) -> exp.Expression:
327317 expression = exp .Literal .number (current_ts ),
328318 )
329319
320+ def _fetch_environment_summaries (
321+ self , where : t .Optional [str | exp .Expression ] = None
322+ ) -> t .List [EnvironmentSummary ]:
323+ return [
324+ self ._environment_summmary_from_row (row )
325+ for row in fetchall (
326+ self .engine_adapter ,
327+ self ._environments_query (
328+ where = where ,
329+ required_fields = list (EnvironmentSummary .all_fields ()),
330+ ),
331+ )
332+ ]
333+
330334
331335def _environment_to_df (environment : Environment ) -> pd .DataFrame :
332336 import pandas as pd
0 commit comments