@@ -91,6 +91,7 @@ def disconnect(self: Self) -> None:
9191 """
9292 if self .client :
9393 self .client .close ()
94+ self .client = None
9495 logger .debug ("MongoDB connection closed." )
9596
9697 def get_collection (self : Self , collection_name : str ) -> Collection | None :
@@ -162,7 +163,6 @@ def write_compare_info(self: Self, compare_info: FullCompareInfo) -> None:
162163 }
163164 document = {"_id" : document_id , ** serialize_compare_result_to_dict (compare_info )}
164165
165- # Insert or update the document
166166 self .collection .update_one ({"_id" : document_id }, {"$set" : document }, upsert = True )
167167 logger .trace ( # type: ignore
168168 "Document for (%s, %s) successfully inserted/updated." ,
@@ -190,10 +190,7 @@ def write_features(self: Self, work: ASTFeatures) -> None:
190190 Args:
191191 work (ASTFeatures): The file for which features are being saved.
192192 """
193- # Forming _id as the file path
194193 document_id = str (work .filepath )
195-
196- # Using function serialize_features_to_dict to convert data
197194 serialized_work = serialize_features_to_dict (work )
198195
199196 document = {
@@ -203,7 +200,6 @@ def write_features(self: Self, work: ASTFeatures) -> None:
203200 "features" : serialized_work ,
204201 }
205202
206- # Insert or update the document
207203 self .collection .update_one ({"_id" : document_id }, {"$set" : document }, upsert = True )
208204 logger .trace ("Document for path %s successfully inserted/updated." , document_id ) # type: ignore
209205
@@ -220,17 +216,13 @@ def get_features(self: Self, work: ASTFeatures) -> ASTFeatures | None:
220216 ASTFeatures | None: Deserialized AST features if found and valid.
221217 """
222218 document_id = str (work .filepath )
223-
224- # Find document in collection
225219 document = self .collection .find_one ({"_id" : document_id })
226220 if not document :
227221 logger .trace ("No features found for file path: %s" , document_id ) # type: ignore
228222 return None
229223 logger .trace ("Features found for file path: %s" , document_id ) # type: ignore
230224
231- # Deserialize and return features
232- features = deserialize_features_from_dict (document ["features" ])
233- return features
225+ return deserialize_features_from_dict (document ["features" ])
234226
235227
236228class MongoReporter (AbstractReporter ):
@@ -257,6 +249,7 @@ def get_result(
257249 work1 (ASTFeatures): Contains the first work metadata.
258250 work2 (ASTFeatures): Contains the second work metadata.
259251 """
252+ work1 , work2 = sorted ([work1 , work2 ])
260253 cache_val = self .repository .get_compare_info (work1 .filepath , work2 .filepath )
261254
262255 if (
0 commit comments