Commits

Jakub Wilk committed b4efe15

kc-apt-file: reduce memory usage when updating.

Comments (0)

Files changed (1)

             )
         fetcher.run()
         for file in files.values():
+            skip = True
             with gzip.open(file.destfile) as file:
-                contents = file.read()
-            skip = True
-            for line in io.BytesIO(contents):
-                if skip:
-                    if line.startswith(b'FILE'):
-                        skip = False
-                else:
-                    filename, packages = parse(line).groups()
-                    for package in [pkg.split(b'/')[-1] for pkg in packages.split(b',')]:
-                        data[package] += [filename]
+                for line in file:
+                    if skip:
+                        if line.startswith(b'FILE'):
+                            skip = False
+                    else:
+                        filename, packages = parse(line).groups()
+                        for package in [pkg.split(b'/')[-1] for pkg in packages.split(b',')]:
+                            data[package] += [filename]
+            contents = None
     finally:
         shutil.rmtree(tmpdir)
     db = kc.DB()
     try:
         for package, filenames in data.items():
             db[package] = zlib.compress(b'\n'.join(filenames), 1)
+            filenames[:] = []
     finally:
         db.close()