r86773 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86772‎ | r86773 | r86774 >
Date:15:09, 23 April 2011
Author:diederik
Status:deferred
Tags:
Comment:
Improve insert performance
Modified paths:
  • /trunk/tools/editor_trends/classes/buffer.py (modified) (history)
  • /trunk/tools/editor_trends/classes/storage.py (modified) (history)
  • /trunk/tools/editor_trends/database/cache.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/classes/buffer.py
@@ -80,7 +80,7 @@
8181 self.n = 0
8282 self.filehandles = [file_utils.create_txt_filehandle(self.rts.txt,
8383 file_id, 'a', 'utf-8') for file_id in xrange(self.rts.max_filehandles)]
84 - self.keys = ['revision_id', 'article_id', 'id', 'username', 'namespace',
 84+ self.keys = ['id', 'article_id', 'revision_id', 'username', 'namespace',
8585 'title', 'timestamp', 'hash', 'revert', 'bot', 'cur_size',
8686 'delta']
8787 self.fh_articles = file_utils.create_txt_filehandle(self.rts.txt,
Index: trunk/tools/editor_trends/classes/storage.py
@@ -120,14 +120,14 @@
121121 assert isinstance(data, dict), 'You need to feed me dictionaries.'
122122 return self.db[self.collection].save(data)
123123
124 - def insert(self, data, qualifiers=None):
 124+ def insert(self, data, qualifiers=None, safe=False):
125125 assert isinstance(data, dict), 'You need to feed me dictionaries.'
126126 data = self.stringify_keys(data)
127127 try:
128128 if qualifiers:
129 - self.db[self.collection].insert(data, qualifiers, safe=True)
 129+ self.db[self.collection].insert(data, qualifiers, safe=safe)
130130 else:
131 - self.db[self.collection].insert(data, safe=True)
 131+ self.db[self.collection].insert(data, safe=safe)
132132 except bson.errors.InvalidDocument, error:
133133 print error
134134 print 'BSON document too large, unable to store %s' % \
Index: trunk/tools/editor_trends/database/cache.py
@@ -54,6 +54,7 @@
5555 def add(self, key, value):
5656 if value == 'NEXT':
5757 self.n += 1
 58+ print self.editors
5859 edits = self.drop_years_no_obs(self.editors[key]['edits'])
5960 self.insert(key, edits, self.editors[key]['username'])
6061 del self.editors[key]
@@ -72,19 +73,7 @@
7374
7475 def insert(self, editor, values, username):
7576 data = {'editor': editor, 'edits': values, 'username': username}
76 - self.db.insert(data)
77 -# '''
78 -# Adding the safe=True statement slows down the insert process but this
79 -# assures that all data will be written.
80 -# '''
81 -# try:
82 -# self.collection.insert({'editor': editor, 'edits': values, 'username': username}, safe=True)
83 -# except bson.errors.InvalidDocument:
84 -# print 'BSON document too large, unable to store %s' % (username)
85 -# except OperationFailure, error:
86 -# print error
87 -# print 'It seems that you are running out of disk space.'
88 -# sys.exit(-1)
 77+ self.db.insert(data, safe=False)
8978
9079 def store(self):
9180 file_utils.store_object(self, settings.binary_location, self.__repr__())