Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7122786
D282.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D282.diff
View Options
diff --git a/swh/storage/db.py b/swh/storage/db.py
--- a/swh/storage/db.py
+++ b/swh/storage/db.py
@@ -8,8 +8,9 @@
import enum
import functools
import json
+import os
import select
-import tempfile
+import threading
from contextlib import contextmanager
@@ -174,16 +175,27 @@
else:
# We don't escape here to make sure we pass literals properly
return str(data)
- with tempfile.TemporaryFile('w+') as f:
+
+ read_file, write_file = os.pipe()
+
+ def writer():
+ cursor = self._cursor(cur)
+ with open(read_file, 'r') as f:
+ cursor.copy_expert('COPY %s (%s) FROM STDIN CSV' % (
+ tblname, ', '.join(columns)), f)
+
+ write_thread = threading.Thread(target=writer)
+ write_thread.start()
+
+ with open(write_file, 'w') as f:
for d in items:
if item_cb is not None:
item_cb(d)
line = [escape(d.get(k)) for k in columns]
f.write(','.join(line))
f.write('\n')
- f.seek(0)
- self._cursor(cur).copy_expert('COPY %s (%s) FROM STDIN CSV' % (
- tblname, ', '.join(columns)), f)
+
+ write_thread.join()
def mktemp(self, tblname, cur=None):
self._cursor(cur).execute('SELECT swh_mktemp(%s)', (tblname,))
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 17, 12:21 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217280
Attached To
D282: db: use a thread instead of a tmpfile to COPY data to postgresql
Event Timeline
Log In to Comment