matrix-org / rust-synapse-compress-state

A tool to compress some state in a Synapse instance's database
https://pypi.org/project/synapse-auto-compressor/
Apache License 2.0
143 stars 33 forks source link

Generates broken insert statement #8

Closed jo-so closed 5 years ago

jo-so commented 5 years ago

Sometime a generated block looks like this:

BEGIN;
DELETE FROM state_group_edges WHERE state_group = 219235;
INSERT INTO state_group_edges (state_group, prev_state_group) VALUES (219235, 219234);
DELETE FROM state_groups_state WHERE state_group = 219235;
INSERT INTO state_groups_state (state_group, room_id, type, state_key, event_id) VALUES
;
COMMIT;

I had the problem with multiple big rooms like #matrix:matrix.org and #Lineage-OS:hackerspaces.be

jo-so commented 5 years ago

Here is the output of the SQL query

SELECT m.id, prev_state_group, type, state_key, s.event_id
FROM state_groups AS m
LEFT JOIN state_groups_state AS s ON (m.id = s.state_group)
LEFT JOIN state_group_edges AS e ON (m.id = e.state_group)
WHERE m.room_id = '!ewSAcClcmSqdLmkCFN:matrix.org'
jo-so commented 5 years ago

Sorry, this was a mistake on my side. I followed the clippy advice which broke the tool:

warning: length comparison to zero
   --> src/main.rs:270:20
    |
270 |                 if new_entry.state_map.len() > 0 {
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `!new_entry.state_map.is_empty()`
    |
    = note: #[warn(clippy::len_zero)] on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero