diff --git a/modules/archive/__init__.py b/modules/archive/__init__.py index f41fa331..e342854b 100644 --- a/modules/archive/__init__.py +++ b/modules/archive/__init__.py @@ -1,3 +1,4 @@ +import itertools import json import pathlib from abc import ABC @@ -62,7 +63,7 @@ def archive_modeler(groups: Dict[str, List[File]], session: Session): if any(lib.is_singlefile_file(i.path) for i in group): archive_groups[stem] = group - count = 0 + count = itertools.cycle(range(101)) for stem, group in archive_groups.items(): readability_file, singlefile_file, readability_json_file, readability_txt_file, screenshot_file = \ match_archive_files(group) @@ -96,8 +97,7 @@ def archive_modeler(groups: Dict[str, List[File]], session: Session): # Remove this group, it will not be processed by other modelers. del groups[stem] - count += 1 - if not count % 100: + if next(count) == 100: # Commit occasionally. session.commit() diff --git a/modules/videos/__init__.py b/modules/videos/__init__.py index d901db1b..f22d008c 100644 --- a/modules/videos/__init__.py +++ b/modules/videos/__init__.py @@ -1,3 +1,4 @@ +import itertools import json import pathlib from abc import ABC @@ -21,8 +22,9 @@ __all__ = ['video_modeler', 'VideoIndexer'] @register_modeler def video_modeler(groups: Dict[str, List[File]], session: Session): + count = itertools.cycle(range(101)) + # Only process groups that contain a video file. - count = 0 local_groups = groups.copy() for stem, group in local_groups.items(): video_file = next((i for i in group if i.mimetype.split('/')[0] == 'video' and i.path.suffix != '.part'), None) @@ -57,8 +59,7 @@ def video_modeler(groups: Dict[str, List[File]], session: Session): # Remove this group, it will not be processed by other modelers. del groups[stem] - count += 1 - if not count % 100: + if next(count) == 100: # Commit occasionally. session.commit()