Skip to content

Commit a8287c5

Browse files
committed
fix: minor improvements to sync
1 parent 5c8bc4e commit a8287c5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

aw-sync/src/sync.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ fn create_datastore(dspath: &PathBuf) -> Datastore {
135135
Datastore::new(pathstr, false)
136136
}
137137

138+
// TODO: Move into tests
138139
fn setup_test(sync_directory: &Path) -> std::io::Result<Vec<Datastore>> {
139140
let mut datastores: Vec<Datastore> = Vec::new();
140141
for n in 0..2 {
@@ -238,7 +239,7 @@ pub fn sync_datastores(
238239
ds_to: &dyn AccessMethod,
239240
is_push: bool,
240241
src_did: Option<&str>,
241-
buckets: &Vec<String>,
242+
buckets: &[String],
242243
) {
243244
// FIXME: "-synced" should only be appended when synced to the local database, not to the
244245
// staging area for local buckets.
@@ -258,7 +259,7 @@ pub fn sync_datastores(
258259
})
259260
// If buckets vec isn't empty, filter out buckets not in the buckets vec
260261
.filter(|bucket| {
261-
if buckets.len() > 0 {
262+
if buckets.is_empty() {
262263
buckets.iter().any(|b_id| b_id == &bucket.id)
263264
} else {
264265
true

aw-sync/tests/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mod sync_tests {
101101
let state = init_teststate();
102102
create_bucket(&state.ds_src, 0);
103103

104-
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &vec![]);
104+
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &[]);
105105

106106
let buckets_src: HashMap<String, Bucket> = state.ds_src.get_buckets().unwrap();
107107
let buckets_dest: HashMap<String, Bucket> = state.ds_dest.get_buckets().unwrap();
@@ -136,7 +136,7 @@ mod sync_tests {
136136
.heartbeat(bucket_id.as_str(), create_event("1"), 1.0)
137137
.unwrap();
138138

139-
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &vec![]);
139+
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &[]);
140140

141141
let all_datastores: Vec<&Datastore> =
142142
[&state.ds_src, &state.ds_dest].iter().cloned().collect();
@@ -150,7 +150,7 @@ mod sync_tests {
150150
.ds_src
151151
.heartbeat(bucket_id.as_str(), create_event("1"), 1.0)
152152
.unwrap();
153-
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &vec![]);
153+
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &[]);
154154

155155
// Check again that new events were indeed synced
156156
check_synced_buckets_equal_to_src(&all_buckets_map);
@@ -163,7 +163,7 @@ mod sync_tests {
163163
let bucket_id = create_bucket(&state.ds_src, 0);
164164
create_events(&state.ds_src, bucket_id.as_str(), 10);
165165

166-
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &vec![]);
166+
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &[]);
167167

168168
let all_datastores: Vec<&Datastore> =
169169
[&state.ds_src, &state.ds_dest].iter().cloned().collect();
@@ -174,7 +174,7 @@ mod sync_tests {
174174

175175
// Add some more events
176176
create_events(&state.ds_src, bucket_id.as_str(), 10);
177-
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &vec![]);
177+
aw_sync::sync_datastores(&state.ds_src, &state.ds_dest, false, None, &[]);
178178

179179
// Check again that new events were indeed synced
180180
check_synced_buckets_equal_to_src(&all_buckets_map);

0 commit comments

Comments
 (0)