wbolster / plyvel

Plyvel, a fast and feature-rich Python interface to LevelDB
https://plyvel.readthedocs.io/
Other
531 stars 76 forks source link

Calling clear() after WriteBatch.write() ? #120

Closed ixje closed 3 years ago

ixje commented 3 years ago

On a WriteBatch, should one call clear() after a write() or is that done implicitly when write()ing? Thanks

wbolster commented 3 years ago

i'm not entirely sure how leveldb operates internally, but generally you should just throw the WriteBatch instance away after you're done with it, and create new one for subsequent operations. the context manager support makes this easy, since there is no need to call .write() at all:

with db.write_batch() as wb:
    for i in xrange(100000):
        wb.put(str(i).encode(), str(i).encode() * 100)
ixje commented 3 years ago

Thanks