fix cache busting

This commit is contained in:
Karol Wypchlo 2021-07-18 09:07:15 +02:00
parent fdee9b46ee
commit 273bcbcb8f
1 changed files with 8 additions and 6 deletions

View File

@ -96,20 +96,22 @@ async def block_skylinks_from_airtable():
return await send_msg(message, force_notify=False) return await send_msg(message, force_notify=False)
print("Searching nginx cache for blocked files") print("Searching nginx cache for blocked files")
cached_files_count = 0 total_cached_files_count = 0
for i in range(0, len(skylinks), 1000): for i in range(0, len(skylinks), 1000):
cached_files_command = ( cached_files_command = (
"find /data/nginx/cache/ -type f | xargs --no-run-if-empty -n1000 grep -Els '^Skynet-Skylink: .*(" "find /data/nginx/cache/ -type f | xargs --no-run-if-empty -n1000 grep -Els '^Skynet-Skylink: ("
+ "|".join(skylinks[i:i+1000]) + "|".join(skylinks[i:i+1000])
+ ")'" + ")'"
) )
cached_files_count += int(exec('docker exec -it nginx bash -c "' + cached_files_command + ' | wc -l"') or 0) cached_files_count = int(exec('docker exec -it nginx bash -c "' + cached_files_command + ' | wc -l"') or 0)
if cached_files_count:
total_cached_files_count+= cached_files_count
exec('docker exec -it nginx bash -c "' + cached_files_command + ' | xargs rm"')
if cached_files_count == 0: if total_cached_files_count == 0:
return print("No nginx cached files matching blocked skylinks were found") return print("No nginx cached files matching blocked skylinks were found")
exec('docker exec -it nginx bash -c "' + cached_files_command + ' | xargs rm"') message = "Purged " + str(total_cached_files_count) + " blocklisted files from nginx cache"
message = "Purged " + str(cached_files_count) + " blocklisted files from nginx cache"
return await send_msg(message) return await send_msg(message)