mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 21:29:59 -05:00
Using itertools.cycle to commit occasionally.
This commit is contained in:
parent
9a47135c99
commit
dad00ad065
2 changed files with 7 additions and 6 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue