16
16
//! Synapse instance's database. Specifically, it aims to reduce the number of
17
17
//! rows that a given room takes up in the `state_groups_state` table.
18
18
19
+ // This file contains configuring config options, which neccessarily means lots
20
+ // of arguments - this hopefully doesn't make the code unclear
21
+ // #[allow(clippy::too_many_arguments)] is therefore used around some functions
22
+
19
23
use pyo3:: { exceptions, prelude:: * } ;
20
24
21
25
#[ cfg( feature = "jemalloc" ) ]
@@ -31,6 +35,7 @@ use string_cache::DefaultAtom as Atom;
31
35
32
36
mod compressor;
33
37
mod database;
38
+ mod graphing;
34
39
35
40
use compressor:: Compressor ;
36
41
use database:: PGEscape ;
@@ -72,6 +77,7 @@ pub struct Config {
72
77
min_saved_rows : Option < i32 > ,
73
78
transactions : bool ,
74
79
level_sizes : LevelSizes ,
80
+ graphs : bool ,
75
81
}
76
82
77
83
impl Config {
@@ -137,6 +143,10 @@ impl Config {
137
143
) )
138
144
. default_value ( "100,50,25" )
139
145
. takes_value ( true ) ,
146
+ ) . arg (
147
+ Arg :: with_name ( "graphs" )
148
+ . short ( "g" )
149
+ . help ( "Whether to produce graphs of state groups before and after compression instead of SQL" )
140
150
) . get_matches ( ) ;
141
151
142
152
let db_url = matches
@@ -164,6 +174,8 @@ impl Config {
164
174
let level_sizes = value_t ! ( matches, "level_sizes" , LevelSizes )
165
175
. unwrap_or_else ( |e| panic ! ( "Unable to parse level_sizes: {}" , e) ) ;
166
176
177
+ let graphs = matches. is_present ( "graphs" ) ;
178
+
167
179
Config {
168
180
db_url : String :: from ( db_url) ,
169
181
output_file,
@@ -172,6 +184,7 @@ impl Config {
172
184
min_saved_rows,
173
185
transactions,
174
186
level_sizes,
187
+ graphs,
175
188
}
176
189
}
177
190
}
@@ -260,6 +273,10 @@ pub fn run(mut config: Config) {
260
273
// transaction.
261
274
262
275
output_sql ( & mut config, & state_group_map, & new_state_group_map) ;
276
+
277
+ if config. graphs {
278
+ graphing:: make_graphs ( state_group_map, new_state_group_map) ;
279
+ }
263
280
}
264
281
265
282
/// Produces SQL code to carry out changes and saves it to file
@@ -440,6 +457,7 @@ impl Config {
440
457
/// Converts string and bool arguments into a Config struct
441
458
///
442
459
/// This function panics if db_url or room_id are empty strings!
460
+ #[ allow( clippy:: too_many_arguments) ]
443
461
pub fn new (
444
462
db_url : String ,
445
463
room_id : String ,
@@ -448,6 +466,7 @@ impl Config {
448
466
min_saved_rows : Option < i32 > ,
449
467
transactions : bool ,
450
468
level_sizes : String ,
469
+ graphs : bool ,
451
470
) -> Result < Config , String > {
452
471
let mut output: Option < File > = None ;
453
472
if let Some ( file) = output_file {
@@ -471,6 +490,7 @@ impl Config {
471
490
min_saved_rows,
472
491
transactions,
473
492
level_sizes,
493
+ graphs,
474
494
} )
475
495
}
476
496
}
@@ -480,14 +500,16 @@ impl Config {
480
500
/// Default arguments are equivalent to using the command line tool
481
501
/// No default's are provided for db_url or room_id since these arguments
482
502
/// are compulsory (so that new() act's like parse_arguments())
503
+ #[ allow( clippy:: too_many_arguments) ]
483
504
#[ pyfunction(
484
505
// db_url has no default
485
506
// room_id has no default
486
507
output_file = "None" ,
487
508
max_state_group = "None" ,
488
509
min_saved_rows = "None" ,
489
510
transactions = false ,
490
- level_sizes = "String::from(\" 100,50,25\" )"
511
+ level_sizes = "String::from(\" 100,50,25\" )" ,
512
+ graphs = false
491
513
) ]
492
514
fn run_compression (
493
515
db_url : String ,
@@ -497,6 +519,7 @@ fn run_compression(
497
519
min_saved_rows : Option < i32 > ,
498
520
transactions : bool ,
499
521
level_sizes : String ,
522
+ graphs : bool ,
500
523
) -> PyResult < ( ) > {
501
524
let config = Config :: new (
502
525
db_url,
@@ -506,6 +529,7 @@ fn run_compression(
506
529
min_saved_rows,
507
530
transactions,
508
531
level_sizes,
532
+ graphs,
509
533
) ;
510
534
match config {
511
535
Err ( e) => Err ( PyErr :: new :: < exceptions:: PyException , _ > ( e) ) ,
0 commit comments