Handle 16 files in parallel

This commit is contained in:
Charlotte 🦝 Delenk 2022-04-23 18:15:51 +01:00
parent ff475d3f12
commit dafd6af9c8
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122

View file

@ -140,11 +140,17 @@ def get_store_hashes() -> set[str]:
async def main() -> None:
store_hashes = get_store_hashes()
sem = asyncio.Semaphore(16)
async for obj_key in list_old_cache_objects():
asyncio.create_task(handle_obj(obj_key))
async def handle_obj(obj_key: str) -> None:
async with sem:
if obj_key.endswith(".narinfo"):
# check if we have the hash locally
if obj_key.split(".")[0] in store_hashes:
continue # yes, dont delete
return # yes, dont delete
narinfo = await get_object(obj_key)
narinfo = NarInfo(narinfo)
if not await narinfo.exists_locally():
@ -155,9 +161,9 @@ async def main() -> None:
realisation = await get_object(obj_key)
realisation = json.loads(realisation)
if not isinstance(realisation, dict):
continue
return
if "outPath" not in realisation:
continue
return
if not await exists_locally("/nix/store/" + realisation["outPath"]):
print(f"Found unused realisation for {realisation['outPath']}")
await delete_object(obj_key)