From b61453ef3485729fde69d6afa3dff071274f6651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 30 Nov 2008 17:22:10 +0100 Subject: [PATCH 1/3] Improve pysocket to reduce the number of call to recv/read --- trytond/pysocket.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/trytond/pysocket.py b/trytond/pysocket.py index e2358f96ec..8018479e78 100644 --- a/trytond/pysocket.py +++ b/trytond/pysocket.py @@ -31,6 +31,7 @@ class PySocket: self.ssl = False self.ssl_sock = None self.connected = False + self.buffer = '' def connect(self, host, port=False): if not port: @@ -79,6 +80,7 @@ class PySocket: self.hostname = hostname self.port = port self.connected = True + self.buffer = '' def disconnect(self): try: @@ -104,6 +106,7 @@ class PySocket: pass self.sock = None self.connected = False + self.buffer = '' def reconnect(self): if self.host and self.port: @@ -113,14 +116,8 @@ class PySocket: def send(self, msg, exception=False, traceback=None): msg = cPickle.dumps([msg, traceback], protocol=2) size = len(msg) - if self.ssl: - self.ssl_sock.write(str(size) + ' ') - else: - self.sock.send(str(size) + ' ') - if self.ssl: - self.ssl_sock.write(exception and "1" or "0") - else: - self.sock.send(exception and "1" or "0") + msg = str(size) + ' ' + (exception and "1" or "0") + msg + size = len(msg) totalsent = 0 while totalsent < size: if self.ssl: @@ -132,12 +129,12 @@ class PySocket: totalsent = totalsent + sent def receive(self): - buf = '' + buf = self.buffer while len(buf) < MAX_LENGHT: if self.ssl: - chunk = self.ssl_sock.read(MAX_LENGHT - len(buf)) + chunk = self.ssl_sock.read(4096) else: - chunk = self.sock.recv(MAX_LENGHT - len(buf)) + chunk = self.sock.recv(4096) if chunk == '': raise RuntimeError, "socket connection broken" buf += chunk @@ -147,9 +144,9 @@ class PySocket: size = int(size) if msg == '': if self.ssl: - msg = self.ssl_sock.read(1) + msg = self.ssl_sock.read(4096) else: - msg = self.sock.recv(1) + msg = self.sock.recv(4096) if msg == '': raise RuntimeError, "socket connection broken" if msg[0] != "0": @@ -165,6 +162,8 @@ class PySocket: if chunk == '': raise RuntimeError, "socket connection broken" msg = msg + chunk + self.buffer = msg[size:] + msg = msg[:size] msgio = StringIO.StringIO(msg) unpickler = cPickle.Unpickler(msgio) # cPickle mechanism to import instances (pickle differs here) From ae3e318457c042ac1ee7f520ec169b1bad9a0b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 30 Nov 2008 17:52:53 +0100 Subject: [PATCH 2/3] Add missing changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index d7df2f4b57..6a091ea0d8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Improve netrpc communication speed * Add contextual domain on inherited views * Allow to use globals in domain and states * Add translate attribute on Selection field From 62c35ebafc78b647d7a5ef8d2e2b61067aaddb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 30 Nov 2008 20:43:40 +0100 Subject: [PATCH 3/3] Fix translation_import for empty translation_ids --- trytond/ir/translation.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index cccf0ede12..72cee67bb6 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -420,12 +420,13 @@ class Translation(OSV, Cacheable): }, context=ctx) translation_ids += ids - cursor.execute('DELETE FROM ir_translation ' \ - 'WHERE module = %s ' \ - 'AND lang = %s ' \ - 'AND id NOT IN ' \ + if translation_ids: + cursor.execute('DELETE FROM ir_translation ' \ + 'WHERE module = %s ' \ + 'AND lang = %s ' \ + 'AND id NOT IN ' \ '(' + ','.join(['%s' for x in translation_ids]) + ')', - (module, lang) + tuple(translation_ids)) + (module, lang) + tuple(translation_ids)) return len(translation_ids) def translation_export(self, cursor, user, lang, module, context=None):