I have application written on C# as a server with one shared folder in SendOnly mode that send files to clients (they works in RecieveOnly mode). How can server knows about completion synchronize in percent of all clients? I think I should use /rest/db/completion on server side?
It seems youâve answered you own question.
Ok. 1 - On server side I should use next request for one folder and all my client
var res = Get($"/db/completion?folder={folder}&device={deviceId}");
devices? Then I should calculate sum of all percents? 2 - How often do I send a request, f.e with 500 ms delay beetwen request?
You can send them serially without delay most likely.
You can the the ui code how it computes the completion I guess.
It required Send request to all client devices (all deviceID of all clients)?
Where I can find the ui code example that computes the completion?
The code is here: https://github.com/syncthing/syncthing/blob/master/gui/default/syncthing/core/syncthingController.js#L484
You can look around for the word compeltion in that file to see whatâs happening. Fields starting with an underscore are artificial fields we compute and are not returned by the API.
OK, Thank you! I will take a look
Hello again!
1 - If I donât do synchronization and try to call the api function GET / rest/db/completion. Does the function return me 0%?
2 - If I synchronize files and call the api function GET /rest/db/completion, will I get 0-100% progress?
3 - If the files have already been synchronized and I call the api function GET /rest/db/completion, will the value be 0 or 100%?
It shows how much of the global state is present on the device (in bytes, except when it only needs to delete files to get to the global state, then itâs 95%).
So If I donât do synchronization or files have already been synchronized and I will try to call the api function GET / rest/db/completion I will get 0%?
I donât understand what you mean by âdonât do synchronizationâ. If you have synchronized, and thus the folder is up-to-date (has the same state as the global state), then itâs 100%. If it has any less than the full global state, itâs less than a 100% (possibly 0% if it has nothing). If you donât know the concept of âglobal stateâ, read https://docs.syncthing.net/users/syncing.html#id2, itâs key to understand completion (there itâs âglobal versionâ instead of state: state is the collection of all items at the global version).
Thanks! Itâs very helpful information!
Ok. I try to sync files between two devices. First device sharing folder in send only mode, second device enabled in recieve only. On recieve side I send REST request via POSTMAN and getting completion and other data = 0⊠But on ui I see progressâŠ
The completion call is for information about other devices. The thing youâre looking at in the UI is for the local device. To get info about the folder locally, use /rest/db/status
.
And Syncthing doesnât return an error when you donât specify a device at all or give an unknown device to /rest/db/completion
. It just pretends that device has nothing. An appropriate error value would likely be more helpful here.
@imsodin ok. I added folder and current device ID. But I didnât see completion data, only bytes and items!
UPD: I change device id from current device to device which I need to sync and get the completionâŠ
@calmh is it some way to calculate progress dynamicly on current device? Could I use https://github.com/syncthing/syncthing/blob/273cc9cef8a647a365219d5b568305aa045418f9/gui/default/syncthing/core/syncthingController.js#L489 algorithm for calculate sync progress?
You canât give the local (I guess thatâs what you mean by current) device id to db/completion as Jakob wrote above, thatâs only for remote devices (thatâs admittedly non-intuitive, but thatâs how it is right now). For information about the local device, use db/status. There we indeed donât expose a percentage on the db/status endpoint, but I mean the info is there: The percentage would be needBytes / globalBytes
.
Ok! Thank you all! Could I ask you one more time please? How to calculate 100 % sync? I saw source in GitHub main repo and find:
if (total == 0) {
$scope.completion[device]._total = 100;
$scope.completion[device]._needBytes = 0;
$scope.completion[device]._needItems = 0;
} else {
$scope.completion[device]._total = Math.floor(100 * (1 - needed / total));
$scope.completion[device]._needBytes = needed;
$scope.completion[device]._needItems = items + deletes;
}
I donât understand how it works in if statement - When the global bytes will equal zero? F.e I get data some like this -
âglobalBytesâ: 105750155, I try next formula for test from your last post:
double needed = 102750155;
double total = 105750155;
double result;
result = (int)Math.Floor(Convert.ToDouble(100 * (needed / total)));
I think I get numbers similar to percentages (97 in my example)