-
Notifications
You must be signed in to change notification settings - Fork 901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update devices each 1 second until chain is not created #1188
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this cause two LoopProc
running with different interval simultaneously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed the fix. Will squash and rebase after approval. |
@@ -463,6 +464,7 @@ void BraveSyncServiceImpl::OnResolvedPreferences(const RecordsList& records) { | |||
bool contains_only_one_device = false; | |||
|
|||
auto sync_devices = sync_prefs_->GetSyncDevices(); | |||
bool waiting_for_second_device = sync_devices->size() < 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a method for this? There are two checks that both check the same condition, but with different values <= 1
vs < 2
and it's confusing to read like that
@AlexeyBarabash can you please add a test for this? |
@darkdh @bridiver |
Pushed a fix for #1188 (comment) comment . |
d157365
to
2b2286a
Compare
Rebased and squashed commits. |
2b2286a
to
190aff1
Compare
@@ -484,7 +487,7 @@ void BraveSyncServiceImpl::OnResolvedPreferences(const RecordsList& records) { | |||
(record->deviceId == this_device_id && | |||
record->action == jslib::SyncRecord::Action::A_DELETE && | |||
actually_merged); | |||
contains_only_one_device = sync_devices->size() < 2 && | |||
contains_only_one_device = sync_devices->have_less_than_two() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this, if there's only one device and it has been deleted, then there are no devices, not one device
@@ -496,6 +499,11 @@ void BraveSyncServiceImpl::OnResolvedPreferences(const RecordsList& records) { | |||
ResetSyncInternal(); | |||
if (contains_only_one_device) | |||
OnResetSync(); | |||
|
|||
if (waiting_for_second_device && !sync_devices->have_less_than_two()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we need this second check and the extra var. Why do we care what the previous size of the sync_devices was? It's also possible that both this_device_deleted
and contains_only_one_device
can both be true. The logic here just doesn't make sense to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't we just do something like this?
diff --git a/components/brave_sync/brave_sync_service_impl.cc b/components/brave_sync/brave_sync_service_impl.cc
index cb76609e..09fb02e7 100644
--- a/components/brave_sync/brave_sync_service_impl.cc
+++ b/components/brave_sync/brave_sync_service_impl.cc
@@ -464,9 +464,7 @@ BraveSyncServiceImpl::PrepareResolvedPreferences(const RecordsList& records) {
}
void BraveSyncServiceImpl::OnResolvedPreferences(const RecordsList& records) {
- const std::string this_device_id = sync_prefs_->GetThisDeviceId();
bool this_device_deleted = false;
- bool contains_only_one_device = false;
auto sync_devices = sync_prefs_->GetSyncDevices();
for (const auto &record : records) {
@@ -480,22 +478,21 @@ void BraveSyncServiceImpl::OnResolvedPreferences(const RecordsList& records) {
record->syncTimestamp.ToJsTime()),
record->action,
&actually_merged);
- this_device_deleted = this_device_deleted ||
- (record->deviceId == this_device_id &&
+ this_device_deleted =
+ record->deviceId == sync_prefs_->GetThisDeviceId() &&
record->action == jslib::SyncRecord::Action::A_DELETE &&
- actually_merged);
- contains_only_one_device = sync_devices->size() < 2 &&
- record->action == jslib::SyncRecord::Action::A_DELETE &&
actually_merged;
+ }
}
} // for each device
sync_prefs_->SetSyncDevices(*sync_devices);
- if (this_device_deleted)
+ if (this_device_deleted || sync_devices->size() == 0) {
ResetSyncInternal();
- if (contains_only_one_device)
- OnResetSync();
+ } else if (sync_devices->size() == 1) {
+ StartLoop(true);
+ }
}
void BraveSyncServiceImpl::OnSyncPrefsChanged(const std::string& pref) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this, if there's only one device and it has been deleted, then there are no devices, not one device
Yes this is a naming issue.
I don't understand why we need this second check and the extra var. Why do we care what the previous size of the sync_devices was?
Because we want to set update interval from 1 to 60 sec if devices size was changed from (0|1) to (2|3|...); and we dont want to touch update interval when devices list was changed from in other cases, like (2|3|4 => 3|4|5) or (3|4|5 => 2|3|4).
The idea is: we cannot have less than two devices and if we have less than two devices we should fetch devices list 1 time/sec to improve the response time.
It's also possible that both this_device_deleted and contains_only_one_device can both be true. The logic here just doesn't make sense to me
There are three things which does BraveSyncServiceImpl::OnResolvedPreferences:
-
We received this device is being deleted, someone on other device in chain pressed the cross near this device.
We mark preferences to set sync state to not enabled. -
When devices list size gets to 1, this means sync chain is no longer exists about to be destroyed. We also mark preferences as sync not enabled.
ResetSyncInternal()
and OnResetSync()
do the same if (sync_devices->size() <= 1)
.
- set fetch sync records interval from 1 sec to 60 sec when sync chain created, devices size was changed from (0|1) to (2|3|...).
Modifying.
|
||
void BraveSyncServiceImpl::StartLoop() { | ||
void BraveSyncServiceImpl::StartLoop(const bool waiting_for_second_device) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use_initial_update_interval
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, sounds more self-explaining.
Pushed fixes. |
2e5f82c
to
0fd2666
Compare
Rebased to current master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
components/brave_sync/sync_devices.h
Outdated
@@ -43,6 +43,7 @@ class SyncDevices { | |||
std::unique_ptr<base::Value> ToValueArrOnly() const; | |||
std::string ToJson() const; | |||
size_t size() const { return devices_.size(); } | |||
bool have_less_than_two() const { return size() < 2; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit, but can we make this has_second_device
and reverse the logic? I think the purpose would be more intuitive and have_less_than_two
just sounds weird to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified this.
f293eaa
to
ca1da86
Compare
Update devices each 1 second until chain is not created
Update devices each 1 second until chain is not created
…ate" This reverts commit f005c59, reversing changes made to 9c45f2f. fix brave/brave-browser#3182
Revert "Merge pull request #1188 from brave/sync_frequent_initial_update"
Revert "Merge pull request #1188 from brave/sync_frequent_initial_update"
Revert "Merge pull request #1188 from brave/sync_frequent_initial_update"
Revert "Merge pull request #1188 from brave/sync_frequent_initial_update"
Fixes brave/brave-browser#2742 , brave/brave-browser#2782 .
Improves response time on sync creation.
Submitter Checklist:
npm test brave_unit_tests && npm test brave_browser_tests
) ongit rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist: