mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-06 13:22:43 +00:00
core: forward based on relations vector (#6464)
* core: forward based on relations vector wip * fix introductions * fix forwarding tests * fix forwarding inside support scope * fix deduplication test * fix more tests * plans, api * live migration wip * enable tests * member locks * api * plans * fix for postgres * fix for postgres * rename predicate * rename predicate * optimize * refactor * fix * check * move part of migration to sql * plans * core: preserve detailed information in relation vectors (#6484) * core: relations vector live migrations; stage 2 migration sql (#6472) * rework forwarding in support scope * move operations inside transactions * set_member_vector_new_relation function * read vector ad-hoc * partition in transaction * fix postgres * postgres schema * api * plans * remove comment * lock before migration computation * refactor * simplify set relations * retreive only support scope members * fix * refactor * fix comment * enable tests * 1 second * for update * locks * fix mask * plans * fix * postgres --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
@@ -34,6 +34,41 @@ $$;
|
||||
|
||||
|
||||
|
||||
CREATE FUNCTION test_chat_schema.migrate_relations_vector_step(state bytea, idx bigint, direction integer, intro_status text) RETURNS bytea
|
||||
LANGUAGE plpgsql IMMUTABLE
|
||||
AS $$
|
||||
DECLARE
|
||||
new_len INT;
|
||||
result BYTEA;
|
||||
status INT;
|
||||
byte_val INT;
|
||||
BEGIN
|
||||
IF idx < 0 THEN
|
||||
RETURN state;
|
||||
END IF;
|
||||
IF intro_status = 're-con' THEN
|
||||
IF direction = 0 THEN status := 2; ELSE status := 3; END IF;
|
||||
ELSIF intro_status = 'to-con' THEN
|
||||
IF direction = 0 THEN status := 3; ELSE status := 2; END IF;
|
||||
ELSIF intro_status = 'con' THEN
|
||||
status := 4;
|
||||
ELSE
|
||||
status := 1;
|
||||
END IF;
|
||||
byte_val := (direction * 8) + status;
|
||||
new_len := GREATEST(length(state), idx + 1);
|
||||
IF new_len > length(state) THEN
|
||||
result := state || (SELECT string_agg('\x00'::BYTEA, ''::BYTEA) FROM generate_series(1, new_len - length(state)));
|
||||
ELSE
|
||||
result := state;
|
||||
END IF;
|
||||
result := set_byte(result, idx::INT, byte_val);
|
||||
RETURN result;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
|
||||
CREATE FUNCTION test_chat_schema.on_group_members_delete_update_summary() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
@@ -85,6 +120,45 @@ END;
|
||||
$$;
|
||||
|
||||
|
||||
|
||||
CREATE FUNCTION test_chat_schema.set_member_vector_new_relation(v bytea, idx bigint, direction integer, status integer) RETURNS bytea
|
||||
LANGUAGE plpgsql IMMUTABLE
|
||||
AS $$
|
||||
DECLARE
|
||||
new_len INT;
|
||||
result BYTEA;
|
||||
byte_val INT;
|
||||
old_byte INT;
|
||||
BEGIN
|
||||
IF idx < 0 THEN
|
||||
RETURN v;
|
||||
END IF;
|
||||
IF idx < length(v) THEN
|
||||
old_byte := get_byte(v, idx::INT);
|
||||
ELSE
|
||||
old_byte := 0;
|
||||
END IF;
|
||||
byte_val := (old_byte & x'F0'::INT) | (direction * 8) | status;
|
||||
new_len := GREATEST(length(v), idx + 1);
|
||||
IF new_len > length(v) THEN
|
||||
result := v || (SELECT string_agg('\x00'::BYTEA, ''::BYTEA) FROM generate_series(1, new_len - length(v)));
|
||||
ELSE
|
||||
result := v;
|
||||
END IF;
|
||||
result := set_byte(result, idx::INT, byte_val);
|
||||
RETURN result;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
|
||||
CREATE AGGREGATE test_chat_schema.migrate_relations_vector(bigint, integer, text) (
|
||||
SFUNC = test_chat_schema.migrate_relations_vector_step,
|
||||
STYPE = bytea,
|
||||
INITCOND = ''
|
||||
);
|
||||
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user