1
1
import os
2
2
import time
3
3
from .entities import *
4
- from typing import Dict , List , Optional
4
+ from typing import Dict , List , Optional , Tuple
5
5
from falkordb import FalkorDB , Path , Node , QueryResult
6
6
7
7
# Configure the logger
10
10
format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
11
11
logger = logging .getLogger (__name__ )
12
12
13
- def list_repos () -> List [str ]:
13
+ def get_repos () -> List [str ]:
14
14
"""
15
15
List processed repositories
16
16
"""
@@ -93,15 +93,40 @@ def enable_backlog(self) -> None:
93
93
Enables the backlog by initializing an empty list.
94
94
"""
95
95
96
- self .backlog = []
96
+ print ("Graph backlog is enabled" )
97
+ self .backlog = {'queries' : [], 'params' : []}
97
98
98
99
def disable_backlog (self ) -> None :
99
100
"""
100
101
Disables the backlog by setting it to None.
101
102
"""
102
103
104
+ print ("Graph backlog is disabled" )
103
105
self .backlog = None
104
106
107
+ def clear_backlog (self ) -> Tuple [List [str ], List [dict ]]:
108
+ """
109
+ Clears and returns the backlog of queries and parameters.
110
+
111
+ Returns:
112
+ Tuple[List[str], List[dict]]: A tuple containing two lists:
113
+ - The first list contains the backlog of queries.
114
+ - The second list contains the backlog of query parameters.
115
+ """
116
+
117
+ if self .backlog :
118
+ queries = self .backlog ['queries' ]
119
+ params = self .backlog ['params' ]
120
+ self .backlog = {'queries' : [], 'params' : []}
121
+ print ("clear_backlog returning:" )
122
+ print (f"queries: { queries } " )
123
+ print (f"params: { params } " )
124
+ return queries , params
125
+ else :
126
+ # Return empty lists if backlog is not initialized or empty
127
+ return [], []
128
+
129
+
105
130
def _query (self , q : str , params : dict ) -> QueryResult :
106
131
"""
107
132
Executes a query on the graph database and logs changes to the backlog if any.
@@ -116,7 +141,9 @@ def _query(self, q: str, params: dict) -> QueryResult:
116
141
117
142
result_set = self .g .query (q , params )
118
143
144
+ print (f"In _query, self.backlog: { self .backlog } " )
119
145
if self .backlog is not None :
146
+ print ("Graph backlog is enabled" )
120
147
# Check if any change occurred in the query results
121
148
change_detected = any (
122
149
getattr (result_set , attr ) > 0
@@ -126,10 +153,14 @@ def _query(self, q: str, params: dict) -> QueryResult:
126
153
'properties_removed' , 'relationships_created'
127
154
]
128
155
)
156
+ print (f"change_detected: { change_detected } " )
129
157
130
158
# Append the query and parameters to the backlog if changes occurred
131
159
if change_detected :
132
- self .backlog .append ((q , params ))
160
+ print (f"logging queries: { q } " )
161
+ print (f"logging params: { params } " )
162
+ self .backlog ['queries' ].append (q )
163
+ self .backlog ['params' ].append (params )
133
164
134
165
return result_set
135
166
@@ -452,7 +483,7 @@ def add_file(self, file: File) -> None:
452
483
res = self ._query (q , params )
453
484
file .id = res .result_set [0 ][0 ]
454
485
455
- def delete_files (self , files : List [dict ], log : bool = False ) -> tuple [str , dict , List [int ]]:
486
+ def delete_files (self , files : List [dict ]) -> tuple [str , dict , List [int ]]:
456
487
"""
457
488
Deletes file(s) from the graph in addition to any other entity
458
489
defined in the file
@@ -476,9 +507,6 @@ def delete_files(self, files: List[dict], log: bool = False) -> tuple[str, dict,
476
507
params = {'files' : files }
477
508
res = self ._query (q , params )
478
509
479
- if log and (res .relationships_deleted > 0 or res .nodes_deleted > 0 ):
480
- return (q , params )
481
-
482
510
return None
483
511
484
512
def get_file (self , path : str , name : str , ext : str ) -> Optional [File ]:
0 commit comments