<s> class BulkInsertBuffer ( object ) : <EOL> def __init__ ( self , doc_cls , maxsize = <NUM_LIT:1000> ) : <EOL> """<STR_LIT>""" <EOL> self . _doc_cls = doc_cls <EOL> self . _maxsize = maxsize <EOL> self . _items = [ ] <EOL> self . _count = <NUM_LIT:0> <EOL> def append ( self , obj ) : <EOL> self . _items . append ( obj ) <EOL> self . _count += <NUM_LIT:1> <EOL> if len ( self . _items ) >= self . _maxsize : <EOL> self . flush ( ) <EOL> def flush ( self ) : <EOL> if len ( self . _items ) : <EOL> self . _doc_cls . objects . insert ( self . _items , load_bulk = False ) <EOL> self . _items = [ ] <EOL> def __len__ ( self ) : <EOL> return len ( self . _items ) <EOL> def count ( self ) : <EOL> return self . _count </s>
