forked from flashbots/mev-inspect-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request flashbots#211 from flashbots/faster-writes
Use COPY to speed up database writes for blocks and traces
- Loading branch information
Showing
4 changed files
with
108 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""This is taken from https://hakibenita.com/fast-load-data-python-postgresql""" | ||
|
||
import io | ||
from typing import Iterator, Optional | ||
|
||
|
||
class StringIteratorIO(io.TextIOBase): | ||
def __init__(self, iter: Iterator[str]): | ||
self._iter = iter | ||
self._buff = "" | ||
|
||
def readable(self) -> bool: | ||
return True | ||
|
||
def _read1(self, n: Optional[int] = None) -> str: | ||
while not self._buff: | ||
try: | ||
self._buff = next(self._iter) | ||
except StopIteration: | ||
break | ||
ret = self._buff[:n] | ||
self._buff = self._buff[len(ret) :] | ||
return ret | ||
|
||
def read(self, n: Optional[int] = None) -> str: | ||
line = [] | ||
if n is None or n < 0: | ||
while True: | ||
m = self._read1() | ||
if not m: | ||
break | ||
line.append(m) | ||
else: | ||
while n > 0: | ||
m = self._read1(n) | ||
if not m: | ||
break | ||
n -= len(m) | ||
line.append(m) | ||
return "".join(line) |