From 0643ebdddd2f58ffe697c73dbf2d4432604b5392 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Sun, 12 Sep 2021 11:49:08 +0300 Subject: [PATCH] Write all COPY data in one go --- pgtricks/pg_dump_splitsort.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pgtricks/pg_dump_splitsort.py b/pgtricks/pg_dump_splitsort.py index c344580..7c82926 100755 --- a/pgtricks/pg_dump_splitsort.py +++ b/pgtricks/pg_dump_splitsort.py @@ -5,7 +5,7 @@ import os import re import sys -from typing import IO, List, Match, Optional, Pattern, Tuple, Union, cast +from typing import IO, List, Match, Optional, Pattern, Tuple, Union, cast, Iterable from pgtricks.mergesort import MergeSort @@ -65,10 +65,10 @@ def flush() -> None: output.writelines(buf) buf[:] = [] - def writeline(line_: str) -> None: + def writelines(lines: Iterable[str]) -> None: if buf: flush() - output.write(line_) + output.writelines(lines) def new_output(filename: str) -> IO[str]: if output: @@ -85,7 +85,7 @@ def new_output(filename: str) -> IO[str]: if line in ('\n', '--\n'): buf.append(line) elif line.startswith('SET search_path = '): - writeline(line) + writelines([line]) else: if matcher.match(DATA_COMMENT_RE, line): counter += 1 @@ -103,12 +103,11 @@ def new_output(filename: str) -> IO[str]: elif 1 <= counter < 9999: counter = 9999 output = new_output('%04d_epilogue.sql' % counter) - writeline(line) + writelines([line]) else: if line == "\\.\n": - for copy_line in copy_lines: - writeline(copy_line) - writeline(line) + writelines(copy_lines) + writelines(line) copy_lines = None else: copy_lines.append(line)