feat: sync multilayer td integration

This commit is contained in:
A 2026-07-15 13:32:06 +08:00
parent 20a310f6ca
commit 766c5db992
491 changed files with 26235 additions and 35340 deletions

View file

@ -0,0 +1,7 @@
DROP TABLE IF EXISTS public.auth_key_session_layers;
ALTER TABLE public.auth_keys
DROP CONSTRAINT IF EXISTS auth_keys_layer_observation_id_valid,
DROP COLUMN IF EXISTS layer_observation_id;
DROP SEQUENCE IF EXISTS public.auth_key_layer_observation_seq;

View file

@ -0,0 +1,38 @@
-- Short-lived, durable per-session invokeWithLayer watermark. The in-process
-- exact-profile registry prevents ordinary replay rollback, while this table
-- closes the durable commit/restart and cross-instance replacement-connection
-- window for client msg_ids that are still fresh enough to be accepted by
-- MTProto. It does not broadcast profile changes into an already-live remote
-- physical connection; that connection remains frozen until its own selector.
CREATE SEQUENCE public.auth_key_layer_observation_seq AS bigint;
ALTER TABLE public.auth_keys
ADD COLUMN layer_observation_id bigint NOT NULL DEFAULT 0,
ADD CONSTRAINT auth_keys_layer_observation_id_valid
CHECK (layer_observation_id >= 0);
CREATE TABLE public.auth_key_session_layers (
raw_auth_key_id bigint NOT NULL,
session_id bigint NOT NULL,
layer integer NOT NULL,
msg_id bigint NOT NULL,
observation_id bigint NOT NULL,
expires_at timestamptz NOT NULL,
PRIMARY KEY (raw_auth_key_id, session_id),
CONSTRAINT auth_key_session_layers_auth_key_fkey
FOREIGN KEY (raw_auth_key_id)
REFERENCES public.auth_keys(auth_key_id)
ON DELETE CASCADE,
CONSTRAINT auth_key_session_layers_layer_valid CHECK (layer > 0),
CONSTRAINT auth_key_session_layers_msg_id_valid
CHECK (
msg_id > 0
AND msg_id % 4 = 0
AND (msg_id & 4294967295) <> 0
),
CONSTRAINT auth_key_session_layers_observation_id_valid
CHECK (observation_id > 0)
);
CREATE INDEX auth_key_session_layers_expiry_idx
ON public.auth_key_session_layers (expires_at, raw_auth_key_id, session_id);