| 305 | |
| 306 | |
| 307 | class _CommitDataCache: |
| 308 | def __init__(self, path): |
| 309 | self.path = path |
| 310 | self.data = {} |
| 311 | if os.path.exists(path): |
| 312 | self.data = self.read_from_disk() |
| 313 | else: |
| 314 | os.makedirs(Path(path).parent, exist_ok=True) |
| 315 | |
| 316 | def get(self, commit): |
| 317 | if commit not in self.data.keys(): |
| 318 | # Fetch and cache the data |
| 319 | self.data[commit] = get_features(commit) |
| 320 | self.write_to_disk() |
| 321 | return self.data[commit] |
| 322 | |
| 323 | def read_from_disk(self): |
| 324 | with open(self.path, "r") as f: |
| 325 | data = json.load(f) |
| 326 | data = {commit: dict_to_features(dct) for commit, dct in data.items()} |
| 327 | return data |
| 328 | |
| 329 | def write_to_disk(self): |
| 330 | data = {commit: features._asdict() for commit, features in self.data.items()} |
| 331 | with open(self.path, "w") as f: |
| 332 | json.dump(data, f) |
no outgoing calls
no test coverage detected
searching dependent graphs…