Skip to content

Commit cfec882

Browse files
committed
swatbotrest: Invalidate all stepfailures lists when pushing new triage
Signed-off-by: Mathieu Dubois-Briand <[email protected]>
1 parent 6f4b3a5 commit cfec882

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

swattool/swatbotrest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def invalidate_stepfailures_cache():
164164
This can be used to force fetching failures on next build, when we suspect
165165
it might have changed remotely.
166166
"""
167-
Session().invalidate_cache(f"{REST_BASE_URL}/stepfailure/")
167+
Session().invalidate_cache(f"{REST_BASE_URL}/stepfailure/", allparams=True)
168168

169169

170170
def get_stepfailures(status: Optional[TriageStatus] = None,

swattool/webrequests.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,35 @@ def save_cookies(self):
5353
with COOKIESFILE.open('wb') as file:
5454
pickle.dump(self.session.cookies, file)
5555

56-
def invalidate_cache(self, url: str):
56+
def invalidate_cache(self, url: str, allparams: bool = False):
5757
"""Invalidate cache for a given URL."""
5858
with cache_lock:
59-
for file in self._get_cache_file_candidates(url):
60-
file.unlink(missing_ok=True)
59+
if allparams:
60+
prefix = self._get_cache_file_prefix(url)
61+
for file in prefix.parent.glob(f"{prefix.name}*"):
62+
file.unlink()
63+
else:
64+
for file in self._get_cache_file_candidates(url):
65+
file.unlink(missing_ok=True)
6166

62-
def _get_cache_file_candidates(self, url: str) -> list[pathlib.Path]:
67+
def _get_cache_file_prefix(self, url: str) -> pathlib.Path:
6368
filestem = url.split('://', 1)[1].replace('/', '_').replace(':', '_')
6469

6570
if len(filestem) > 100:
6671
hashname = hashlib.sha256(filestem.encode(), usedforsecurity=False)
6772
filestem = hashname.hexdigest()
6873

74+
return utils.CACHEDIR / filestem
75+
76+
def _get_cache_file_candidates(self, url: str) -> list[pathlib.Path]:
77+
prefix = self._get_cache_file_prefix(url)
78+
6979
candidates = [
70-
utils.CACHEDIR / f"{filestem}.gz",
71-
utils.CACHEDIR / filestem,
80+
prefix.parent / f'{prefix.name}.gz',
81+
prefix,
7282

7383
# For compatibility with old cache files
74-
utils.CACHEDIR / f"{filestem}.json",
84+
prefix.parent / f'{prefix.name}.json',
7585
]
7686

7787
return candidates

0 commit comments

Comments
 (0)