mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-20 02:24:54 +03:00
Make event_ids smaller
This commit is contained in:
parent
a99c2f56b5
commit
1466adf427
4 changed files with 31 additions and 5 deletions
|
@ -14,9 +14,9 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import string
|
||||||
|
|
||||||
from synapse.types import EventID
|
from synapse.types import EventID
|
||||||
from synapse.util.stringutils import random_string
|
|
||||||
|
|
||||||
from . import EventBase, FrozenEvent, _event_dict_property
|
from . import EventBase, FrozenEvent, _event_dict_property
|
||||||
|
|
||||||
|
@ -49,10 +49,10 @@ class EventBuilderFactory(object):
|
||||||
self.event_id_count = 0
|
self.event_id_count = 0
|
||||||
|
|
||||||
def create_event_id(self):
|
def create_event_id(self):
|
||||||
i = str(self.event_id_count)
|
i = self.event_id_count
|
||||||
self.event_id_count += 1
|
self.event_id_count += 1
|
||||||
|
|
||||||
local_part = random_string(3) + str(i)
|
local_part = _encode_id(i)
|
||||||
|
|
||||||
e_id = EventID(local_part, self.hostname)
|
e_id = EventID(local_part, self.hostname)
|
||||||
|
|
||||||
|
@ -73,3 +73,19 @@ class EventBuilderFactory(object):
|
||||||
key_values["signatures"] = {}
|
key_values["signatures"] = {}
|
||||||
|
|
||||||
return EventBuilder(key_values=key_values,)
|
return EventBuilder(key_values=key_values,)
|
||||||
|
|
||||||
|
|
||||||
|
def _numberToBase(n, b):
|
||||||
|
if n == 0:
|
||||||
|
return [0]
|
||||||
|
digits = []
|
||||||
|
while n:
|
||||||
|
digits.append(int(n % b))
|
||||||
|
n //= b
|
||||||
|
return digits[::-1]
|
||||||
|
|
||||||
|
|
||||||
|
def _encode_id(i):
|
||||||
|
digits = string.digits + string.ascii_letters
|
||||||
|
val_slice = _numberToBase(i, len(digits))
|
||||||
|
return "".join(digits[x] for x in val_slice)
|
||||||
|
|
|
@ -26,7 +26,7 @@ from synapse.crypto.event_signing import check_event_content_hash
|
||||||
from synapse.events import FrozenEvent
|
from synapse.events import FrozenEvent
|
||||||
from synapse.events.utils import prune_event
|
from synapse.events.utils import prune_event
|
||||||
from synapse.http.servlet import assert_params_in_dict
|
from synapse.http.servlet import assert_params_in_dict
|
||||||
from synapse.types import get_domain_from_id
|
from synapse.types import get_domain_from_id, EventID
|
||||||
from synapse.util import logcontext, unwrapFirstError
|
from synapse.util import logcontext, unwrapFirstError
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -326,6 +326,14 @@ def event_from_pdu_json(pdu_json, outlier=False):
|
||||||
elif depth > MAX_DEPTH:
|
elif depth > MAX_DEPTH:
|
||||||
raise SynapseError(400, "Depth too large", Codes.BAD_JSON)
|
raise SynapseError(400, "Depth too large", Codes.BAD_JSON)
|
||||||
|
|
||||||
|
event_id = pdu_json["event_id"]
|
||||||
|
if event_id[0] != "$":
|
||||||
|
pdu_json["event_id"] = EventID(
|
||||||
|
event_id,
|
||||||
|
get_domain_from_id(pdu_json["sender"]),
|
||||||
|
).to_string()
|
||||||
|
event_id = pdu_json["event_id"]
|
||||||
|
|
||||||
dtab = pdu_json.get("unsigned", {}).pop("dtab", None)
|
dtab = pdu_json.get("unsigned", {}).pop("dtab", None)
|
||||||
|
|
||||||
if dtab:
|
if dtab:
|
||||||
|
|
|
@ -20,6 +20,7 @@ server protocol.
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from synapse.types import get_localpart_from_id
|
||||||
from synapse.util.jsonobject import JsonEncodedObject
|
from synapse.util.jsonobject import JsonEncodedObject
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -129,6 +130,8 @@ def _mangle_pdu(pdu_json):
|
||||||
pdu_json["auth_events"] = list(_strip_hashes(pdu_json["auth_events"]))
|
pdu_json["auth_events"] = list(_strip_hashes(pdu_json["auth_events"]))
|
||||||
pdu_json["prev_events"] = list(_strip_hashes(pdu_json["prev_events"]))
|
pdu_json["prev_events"] = list(_strip_hashes(pdu_json["prev_events"]))
|
||||||
|
|
||||||
|
pdu_json["event_id"] = get_localpart_from_id(pdu_json["event_id"])
|
||||||
|
|
||||||
destinations = pdu_json["unsigned"].pop("destinations", None)
|
destinations = pdu_json["unsigned"].pop("destinations", None)
|
||||||
if destinations:
|
if destinations:
|
||||||
new_destinations = {}
|
new_destinations = {}
|
||||||
|
|
|
@ -1442,7 +1442,6 @@ class FederationHandler(BaseHandler):
|
||||||
if not joined:
|
if not joined:
|
||||||
logger.error("Giving up on trying to auto-accept invite: too many attempts")
|
logger.error("Giving up on trying to auto-accept invite: too many attempts")
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def do_remotely_reject_invite(self, target_hosts, room_id, user_id):
|
def do_remotely_reject_invite(self, target_hosts, room_id, user_id):
|
||||||
origin, event = yield self._make_and_verify_event(
|
origin, event = yield self._make_and_verify_event(
|
||||||
|
|
Loading…
Reference in a new issue