@@ -150,12 +150,13 @@ def append_tx(self, tx_data: dict[str, Any]) -> None:
150150 with self ._lock :
151151 self ._tx_log .append (tx_data )
152152
153- def get_tx_log (self , limit : int = 100 , offset : int = 0 ) -> list [dict [str , Any ]]:
153+ def get_tx_log (self , session_id : str , limit : int = 100 , offset : int = 0 ) -> list [dict [str , Any ]]:
154154 """
155155 Retrieves and returns a portion of the transaction log. The transaction log is accessed in
156156 reverse order of insertion, i.e., the most recently added item is the first in the result.
157157
158158 Args:
159+ session_id (str): The identifier of the session whose transactions should be retrieved.
159160 limit (int): The maximum number of transaction log entries to be retrieved. Default is 100.
160161 offset (int): The starting position relative to the most recent entry that determines where to begin
161162 retrieving the log entries. Default is 0.
@@ -165,7 +166,9 @@ def get_tx_log(self, limit: int = 100, offset: int = 0) -> list[dict[str, Any]]:
165166 contain details of individual transaction log entries.
166167 """
167168 with self ._lock :
168- return list (reversed (self ._tx_log ))[offset : offset + limit ]
169+ reversed_log = reversed (self ._tx_log )
170+ filtered = [tx for tx in reversed_log if tx .get ("session_id" ) == session_id ]
171+ return filtered [offset : offset + limit ]
169172
170173 def delete_session (self , session_id : str ) -> list [str ]:
171174 """
@@ -186,26 +189,6 @@ def delete_session(self, session_id: str) -> list[str]:
186189 del self ._store [fid ]
187190 return to_delete
188191
189- def remove_last_tx (self , count : int ) -> None :
190- """
191- Removes a specified number of the most recent transactions from the transaction
192- log. If the number of transactions to remove exceeds the current size of the
193- log, the entire log will be cleared.
194-
195- Args:
196- count (int): The number of transactions to remove. Must be a positive integer.
197-
198- Returns:
199- None
200- """
201- with self ._lock :
202- if count <= 0 :
203- return
204- if count >= len (self ._tx_log ):
205- self ._tx_log .clear ()
206- else :
207- self ._tx_log = self ._tx_log [:- count ]
208-
209192 def get_session_facts (self , session_id : str ) -> list [dict [str , Any ]]:
210193 """
211194 Retrieves all facts associated with a specific session.
@@ -222,6 +205,25 @@ def get_session_facts(self, session_id: str) -> list[dict[str, Any]]:
222205 """
223206 return [f for f in self ._store .values () if f .get ("session_id" ) == session_id ]
224207
208+ def delete_txs (self , tx_uuids : list [str ]) -> None :
209+ """
210+ Removes a list of transactions from the transaction log whose session IDs match the provided
211+ transaction IDs. If the provided list is empty, no transactions are processed.
212+
213+ Args:
214+ tx_uuids (list[str]): A list of transaction UUIDs to be removed from the log.
215+
216+ Returns:
217+ None
218+ """
219+ if not tx_uuids :
220+ return
221+
222+ with self ._lock :
223+ ids_to_delete = set (tx_uuids )
224+
225+ self ._tx_log = [tx for tx in self ._tx_log if tx ["uuid" ] not in ids_to_delete ]
226+
225227 def close (self ) -> None :
226228 """
227229 Closes the current open resource or connection.
@@ -381,12 +383,13 @@ async def append_tx(self, tx_data: dict[str, Any]) -> None:
381383 async with self ._lock :
382384 self ._tx_log .append (tx_data )
383385
384- async def get_tx_log (self , limit : int = 100 , offset : int = 0 ) -> list [dict [str , Any ]]:
386+ async def get_tx_log (self , session_id : str , limit : int = 100 , offset : int = 0 ) -> list [dict [str , Any ]]:
385387 """
386388 Asynchronously retrieves and returns a portion of the transaction log. The transaction log is accessed in
387389 reverse order of insertion, i.e., the most recently added item is the first in the result.
388390
389391 Args:
392+ session_id (str): The identifier of the session whose transactions should be retrieved.
390393 limit (int): The maximum number of transaction log entries to be retrieved. Default is 100.
391394 offset (int): The starting position relative to the most recent entry that determines where to begin
392395 retrieving the log entries. Default is 0.
@@ -396,7 +399,9 @@ async def get_tx_log(self, limit: int = 100, offset: int = 0) -> list[dict[str,
396399 contain details of individual transaction log entries.
397400 """
398401 async with self ._lock :
399- return list (reversed (self ._tx_log ))[offset : offset + limit ]
402+ reversed_log = reversed (self ._tx_log )
403+ filtered = [tx for tx in reversed_log if tx .get ("session_id" ) == session_id ]
404+ return filtered [offset : offset + limit ]
400405
401406 async def delete_session (self , session_id : str ) -> list [str ]:
402407 """
@@ -417,27 +422,6 @@ async def delete_session(self, session_id: str) -> list[str]:
417422 del self ._store [fid ]
418423 return to_delete
419424
420- async def remove_last_tx (self , count : int ) -> None :
421- """
422- Asynchronously removes a specified number of the most recent transactions from the transaction
423- log. If the number of transactions to remove exceeds the current size of the
424- log, the entire log will be cleared.
425-
426- Args:
427- count (int): The number of transactions to remove. Must be a positive integer.
428-
429- Returns:
430- None
431- """
432- async with self ._lock :
433- if count <= 0 :
434- return
435-
436- if count >= len (self ._tx_log ):
437- self ._tx_log .clear ()
438- else :
439- self ._tx_log = self ._tx_log [:- count ]
440-
441425 async def get_session_facts (self , session_id : str ) -> list [dict [str , Any ]]:
442426 """
443427 Asynchronously retrieves all facts associated with a specific session.
@@ -454,6 +438,25 @@ async def get_session_facts(self, session_id: str) -> list[dict[str, Any]]:
454438 """
455439 return [f for f in self ._store .values () if f .get ("session_id" ) == session_id ]
456440
441+ async def delete_txs (self , tx_uuids : list [str ]) -> None :
442+ """
443+ Asynchronously removes a list of transactions from the transaction log whose session IDs match the provided
444+ transaction IDs. If the provided list is empty, no transactions are processed.
445+
446+ Args:
447+ tx_uuids (list[str]): A list of transaction UUIDs to be removed from the log.
448+
449+ Returns:
450+ None
451+ """
452+ if not tx_uuids :
453+ return
454+
455+ async with self ._lock :
456+ ids_to_delete = set (tx_uuids )
457+
458+ self ._tx_log = [tx for tx in self ._tx_log if tx ["uuid" ] not in ids_to_delete ]
459+
457460 async def close (self ) -> None :
458461 """
459462 Asynchronously closes the current open resource or connection.
0 commit comments