mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 22:49:29 -05:00
Move encoding and decoding of JSON into storage layer
This commit is contained in:
parent
ffad75bd62
commit
bc9e69e160
@ -19,10 +19,7 @@ from twisted.internet import defer
|
|||||||
from httppusher import HttpPusher
|
from httppusher import HttpPusher
|
||||||
from synapse.push import PusherConfigException
|
from synapse.push import PusherConfigException
|
||||||
|
|
||||||
from syutil.jsonutil import encode_canonical_json
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import simplejson as json
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -52,8 +49,6 @@ class PusherPool:
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def start(self):
|
def start(self):
|
||||||
pushers = yield self.store.get_all_pushers()
|
pushers = yield self.store.get_all_pushers()
|
||||||
for p in pushers:
|
|
||||||
p['data'] = json.loads(p['data'])
|
|
||||||
self._start_pushers(pushers)
|
self._start_pushers(pushers)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@ -98,7 +93,7 @@ class PusherPool:
|
|||||||
pushkey=pushkey,
|
pushkey=pushkey,
|
||||||
pushkey_ts=self.hs.get_clock().time_msec(),
|
pushkey_ts=self.hs.get_clock().time_msec(),
|
||||||
lang=lang,
|
lang=lang,
|
||||||
data=encode_canonical_json(data).decode("UTF-8"),
|
data=data,
|
||||||
)
|
)
|
||||||
self._refresh_pusher((app_id, pushkey))
|
self._refresh_pusher((app_id, pushkey))
|
||||||
|
|
||||||
@ -129,7 +124,6 @@ class PusherPool:
|
|||||||
p = yield self.store.get_pushers_by_app_id_and_pushkey(
|
p = yield self.store.get_pushers_by_app_id_and_pushkey(
|
||||||
app_id_pushkey
|
app_id_pushkey
|
||||||
)
|
)
|
||||||
p['data'] = json.loads(p['data'])
|
|
||||||
|
|
||||||
self._start_pushers([p])
|
self._start_pushers([p])
|
||||||
|
|
||||||
|
@ -20,7 +20,10 @@ from twisted.internet import defer
|
|||||||
|
|
||||||
from synapse.api.errors import StoreError
|
from synapse.api.errors import StoreError
|
||||||
|
|
||||||
|
from syutil.jsonutil import encode_canonical_json
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -52,7 +55,7 @@ class PusherStore(SQLBaseStore):
|
|||||||
"device_display_name": r[6],
|
"device_display_name": r[6],
|
||||||
"pushkey": r[7],
|
"pushkey": r[7],
|
||||||
"pushkey_ts": r[8],
|
"pushkey_ts": r[8],
|
||||||
"data": r[9],
|
"data": json.loads(r[9]),
|
||||||
"last_token": r[10],
|
"last_token": r[10],
|
||||||
"last_success": r[11],
|
"last_success": r[11],
|
||||||
"failing_since": r[12]
|
"failing_since": r[12]
|
||||||
@ -84,7 +87,7 @@ class PusherStore(SQLBaseStore):
|
|||||||
"device_display_name": r[6],
|
"device_display_name": r[6],
|
||||||
"pushkey": r[7],
|
"pushkey": r[7],
|
||||||
"pushkey_ts": r[8],
|
"pushkey_ts": r[8],
|
||||||
"data": r[9],
|
"data": json.loads(r[9]),
|
||||||
"last_token": r[10],
|
"last_token": r[10],
|
||||||
"last_success": r[11],
|
"last_success": r[11],
|
||||||
"failing_since": r[12]
|
"failing_since": r[12]
|
||||||
@ -114,7 +117,7 @@ class PusherStore(SQLBaseStore):
|
|||||||
device_display_name=device_display_name,
|
device_display_name=device_display_name,
|
||||||
ts=pushkey_ts,
|
ts=pushkey_ts,
|
||||||
lang=lang,
|
lang=lang,
|
||||||
data=data
|
data=encode_canonical_json(data).decode("UTF-8"),
|
||||||
),
|
),
|
||||||
insertion_values=dict(
|
insertion_values=dict(
|
||||||
id=next_id,
|
id=next_id,
|
||||||
@ -165,20 +168,3 @@ class PusherStore(SQLBaseStore):
|
|||||||
class PushersTable(Table):
|
class PushersTable(Table):
|
||||||
table_name = "pushers"
|
table_name = "pushers"
|
||||||
|
|
||||||
fields = [
|
|
||||||
"id",
|
|
||||||
"user_name",
|
|
||||||
"kind",
|
|
||||||
"profile_tag",
|
|
||||||
"app_id",
|
|
||||||
"app_display_name",
|
|
||||||
"device_display_name",
|
|
||||||
"pushkey",
|
|
||||||
"pushkey_ts",
|
|
||||||
"data",
|
|
||||||
"last_token",
|
|
||||||
"last_success",
|
|
||||||
"failing_since"
|
|
||||||
]
|
|
||||||
|
|
||||||
EntryType = collections.namedtuple("PusherEntry", fields)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user