IMDb import: fix progress reporting

Because we calculated the percentage based on the number of lines we
need to yield once per line, otherwise the count is off.
This commit is contained in:
ducklet 2023-02-04 14:12:36 +01:00
parent e84a6bc865
commit 69643455a6

View file

@ -177,13 +177,14 @@ def read_ratings_as_mapping(path: Path):
return {r[0]: (round(100 * (float(r[1]) - 1) / 9), int(r[2])) for r in rows} return {r[0]: (round(100 * (float(r[1]) - 1) / 9), int(r[2])) for r in rows}
def read_basics(path: Path): def read_basics(path: Path) -> Generator[Movie | None, None, None]:
mtime = gz_mtime(path) mtime = gz_mtime(path)
rows = read_imdb_tsv(path, BasicRow) rows = read_imdb_tsv(path, BasicRow)
for row in rows: for row in rows:
if row.startYear is None: if row.startYear is None:
log.debug("Skipping movie, missing year: %s", row) log.debug("Skipping movie, missing year: %s", row)
yield None
continue continue
m = row.as_movie() m = row.as_movie()
@ -210,6 +211,9 @@ async def import_from_file(*, basics_path: Path, ratings_path: Path):
log.info("⏳ Imported %s%%", round(perc, 1)) log.info("⏳ Imported %s%%", round(perc, 1))
perc_next_report += perc_step perc_next_report += perc_step
if m is None:
continue
if m.media_type not in { if m.media_type not in {
"Movie", "Movie",
"Short", "Short",
@ -234,6 +238,7 @@ async def import_from_file(*, basics_path: Path, ratings_path: Path):
await add_or_update_many_movies(chunk) await add_or_update_many_movies(chunk)
chunk = [] chunk = []
log.info("👍 Imported 100%")
await db.set_import_progress(100) await db.set_import_progress(100)