mirror of
https://codeberg.org/icewind/log-archiver.git
synced 2026-06-03 09:34:09 +02:00
index players
This commit is contained in:
parent
0c7cf53f9c
commit
56a3e3d823
1 changed files with 26 additions and 1 deletions
27
schema.sql
27
schema.sql
|
|
@ -11,4 +11,29 @@ CREATE INDEX logs_raw_id_idx
|
|||
ON logs_raw USING BTREE (id);
|
||||
|
||||
CREATE INDEX logs_raw_success_idx
|
||||
ON logs_raw USING BTREE ((json->>'success'));
|
||||
ON logs_raw USING BTREE ((json->>'success'));
|
||||
|
||||
-- convert STEAM_0:X:YYYYYYYY and [U:1:XXXXXXX] into only [U:1:XXXXXXX]
|
||||
|
||||
CREATE FUNCTION normalize_steam_id(val TEXT) RETURNS TEXT AS $$
|
||||
BEGIN
|
||||
IF substr(val, 0, 6) = 'STEAM' THEN
|
||||
return '[U:1:' || (substr(val, 9, 1)::BIGINT + substr(val, 11)::BIGINT * 2)::TEXT || ']';
|
||||
ELSE
|
||||
return val;
|
||||
END IF;
|
||||
END; $$
|
||||
LANGUAGE PLPGSQL;
|
||||
|
||||
-- get an array of the normalized steamids of all players in a log
|
||||
|
||||
CREATE FUNCTION extract_players(log JSONB) RETURNS TEXT[] AS $$
|
||||
BEGIN
|
||||
return ARRAY(SELECT normalize_steam_id(jsonb_object_keys(log->'players')));
|
||||
END; $$
|
||||
LANGUAGE PLPGSQL IMMUTABLE;
|
||||
|
||||
CREATE INDEX logs_raw_players_idx
|
||||
ON logs_raw USING GIN (extract_players(json));
|
||||
|
||||
-- usage: select id from logs_raw where extract_players(json) @> ARRAY['[U:1:64229260]'];
|
||||
Loading…
Add table
Add a link
Reference in a new issue