mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 08:16:02 -04:00
Use static JSONEncoders
using json.dumps with custom options requires us to create a new JSONEncoder on each call. It's more efficient to create one upfront and reuse it.
This commit is contained in:
parent
88cc9cc69e
commit
05630758f2
4 changed files with 34 additions and 20 deletions
|
@ -24,6 +24,8 @@ import simplejson
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_json_encoder = simplejson.JSONEncoder(namedtuple_as_object=False)
|
||||
|
||||
|
||||
class Command(object):
|
||||
"""The base command class.
|
||||
|
@ -107,7 +109,7 @@ class RdataCommand(Command):
|
|||
return " ".join((
|
||||
self.stream_name,
|
||||
str(self.token) if self.token is not None else "batch",
|
||||
simplejson.dumps(self.row, namedtuple_as_object=False),
|
||||
_json_encoder.dumps(self.row),
|
||||
))
|
||||
|
||||
|
||||
|
@ -302,7 +304,7 @@ class InvalidateCacheCommand(Command):
|
|||
|
||||
def to_line(self):
|
||||
return " ".join((
|
||||
self.cache_func, simplejson.dumps(self.keys, namedtuple_as_object=False)
|
||||
self.cache_func, _json_encoder.encode(self.keys),
|
||||
))
|
||||
|
||||
|
||||
|
@ -334,7 +336,7 @@ class UserIpCommand(Command):
|
|||
)
|
||||
|
||||
def to_line(self):
|
||||
return self.user_id + " " + simplejson.dumps((
|
||||
return self.user_id + " " + _json_encoder.encode((
|
||||
self.access_token, self.ip, self.user_agent, self.device_id,
|
||||
self.last_seen,
|
||||
))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue