Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Synapse Compress State
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Synapse Compress State
Commits
d764082d
Commit
d764082d
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Add optional max_state_group param
parent
b9be6c5e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/database.rs
+34
-15
34 additions, 15 deletions
src/database.rs
src/main.rs
+12
-1
12 additions, 1 deletion
src/main.rs
with
46 additions
and
16 deletions
src/database.rs
+
34
−
15
View file @
d764082d
...
...
@@ -26,10 +26,14 @@ use StateGroupEntry;
/// Fetch the entries in state_groups_state (and their prev groups) for the
/// given `room_id` by connecting to the postgres database at `db_url`.
pub
fn
get_data_from_db
(
db_url
:
&
str
,
room_id
:
&
str
)
->
BTreeMap
<
i64
,
StateGroupEntry
>
{
pub
fn
get_data_from_db
(
db_url
:
&
str
,
room_id
:
&
str
,
max_state_group
:
Option
<
i64
>
,
)
->
BTreeMap
<
i64
,
StateGroupEntry
>
{
let
conn
=
Connection
::
connect
(
db_url
,
TlsMode
::
None
)
.unwrap
();
let
mut
state_group_map
=
get_initial_data_from_db
(
&
conn
,
room_id
);
let
mut
state_group_map
=
get_initial_data_from_db
(
&
conn
,
room_id
,
max_state_group
);
println!
(
"Got initial state from database. Checking for any missing state groups..."
);
...
...
@@ -69,21 +73,36 @@ pub fn get_data_from_db(db_url: &str, room_id: &str) -> BTreeMap<i64, StateGroup
/// Fetch the entries in state_groups_state (and their prev groups) for the
/// given `room_id` by fetching all state with the given `room_id`.
fn
get_initial_data_from_db
(
conn
:
&
Connection
,
room_id
:
&
str
)
->
BTreeMap
<
i64
,
StateGroupEntry
>
{
let
stmt
=
conn
.prepare
(
r#"
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 = $1
"#
,
)
.unwrap
();
fn
get_initial_data_from_db
(
conn
:
&
Connection
,
room_id
:
&
str
,
max_state_group
:
Option
<
i64
>
,
)
->
BTreeMap
<
i64
,
StateGroupEntry
>
{
let
sql
=
format!
(
r#"
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 = $1 {}
"#
,
if
max_state_group
.is_some
()
{
"AND state_group <= $2"
}
else
{
""
}
);
let
stmt
=
conn
.prepare
(
&
sql
)
.unwrap
();
let
trans
=
conn
.transaction
()
.unwrap
();
let
mut
rows
=
stmt
.lazy_query
(
&
trans
,
&
[
&
room_id
],
1000
)
.unwrap
();
let
mut
rows
=
if
let
Some
(
s
)
=
max_state_group
{
stmt
.lazy_query
(
&
trans
,
&
[
&
room_id
,
&
s
],
1000
)
}
else
{
stmt
.lazy_query
(
&
trans
,
&
[
&
room_id
],
1000
)
}
.unwrap
();
let
mut
state_group_map
:
BTreeMap
<
i64
,
StateGroupEntry
>
=
BTreeMap
::
new
();
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
12
−
1
View file @
d764082d
...
...
@@ -124,6 +124,12 @@ fn main() {
.help
(
"The room to process"
)
.takes_value
(
true
)
.required
(
true
),
)
.arg
(
Arg
::
with_name
(
"max_state_group"
)
.short
(
"s"
)
.help
(
"The maximum state group to process up to"
)
.takes_value
(
true
)
.required
(
false
),
)
.arg
(
Arg
::
with_name
(
"output_file"
)
.short
(
"o"
)
...
...
@@ -161,17 +167,22 @@ fn main() {
let
mut
output_file
=
matches
.value_of
(
"output_file"
)
.map
(|
path
|
File
::
create
(
path
)
.unwrap
());
let
room_id
=
matches
.value_of
(
"room_id"
)
.expect
(
"room_id should be required since no file"
);
let
max_state_group
=
matches
.value_of
(
"max_state_group"
)
.map
(|
s
|
s
.parse
()
.expect
(
"max_state_group must be an integer"
));
let
transactions
=
matches
.is_present
(
"transactions"
);
let
level_sizes
=
value_t_or_exit!
(
matches
,
"level_sizes"
,
LevelSizes
);
// First we need to get the current state groups
println!
(
"Fetching state from DB for room '{}'..."
,
room_id
);
let
state_group_map
=
database
::
get_data_from_db
(
db_url
,
room_id
);
let
state_group_map
=
database
::
get_data_from_db
(
db_url
,
room_id
,
max_state_group
);
println!
(
"Number of state groups: {}"
,
state_group_map
.len
());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment