@@ -400,6 +400,9 @@ def _store_fingerprint(conn: duckdb.DuckDBPyConnection, fingerprint: str) -> Non
400400 conn .execute ("INSERT INTO osmsg_run_meta VALUES (?)" , [fingerprint ])
401401
402402
403+ _FILE_FORMATS = frozenset ({"parquet" , "csv" , "json" , "markdown" })
404+
405+
403406def _finalize (
404407 cfg : RunConfig ,
405408 conn : duckdb .DuckDBPyConnection ,
@@ -418,18 +421,22 @@ def _finalize(
418421 raise NoDataFoundError ("No stats produced for the requested time range." )
419422 _store_fingerprint (conn , fingerprint )
420423
421- if cfg .changeset or cfg .hashtags :
422- attach_metadata (conn , rows )
423- if cfg .additional_tags or cfg .tag_mode != "none" or cfg .length_tags :
424- attach_tag_stats (
425- conn ,
426- rows ,
427- additional_tags = cfg .additional_tags ,
428- tag_mode = cfg .tag_mode ,
429- length_tags = cfg .length_tags ,
430- )
431- if cfg .tm_stats :
432- rows = tm .enrich (rows )
424+ # Per-user metadata/tag enrichment feeds only the file-format writers; a psql push writes the raw
425+ # tables and never reads these rows. Skip it when no file format is requested, so a psql-only run
426+ # never materializes every row's tag_stats JSON at once (multi-GB on a large store).
427+ if _FILE_FORMATS & set (cfg .formats ) or cfg .summary :
428+ if cfg .changeset or cfg .hashtags :
429+ attach_metadata (conn , rows )
430+ if cfg .additional_tags or cfg .tag_mode != "none" or cfg .length_tags :
431+ attach_tag_stats (
432+ conn ,
433+ rows ,
434+ additional_tags = cfg .additional_tags ,
435+ tag_mode = cfg .tag_mode ,
436+ length_tags = cfg .length_tags ,
437+ )
438+ if cfg .tm_stats :
439+ rows = tm .enrich (rows )
433440
434441 out = cfg .output_dir
435442 written : dict [str , str ] = {}
0 commit comments