MStadlmeier / drivesync

Google Drive synchronization for Linux
MIT License
197 stars 26 forks source link

Sync takes a long time #26

Closed Gorden-Tseng closed 4 years ago

Gorden-Tseng commented 5 years ago

When I run ruby drivesync.rb, the console will hang for about 5 minutes before outputting the "Sync complete." message, even if everything is already synced. Is this normal?

Here's an example, I first print the time to show you how long the sync takes:

$ date "+%H:%M:%S"; ruby drivesync.rb 17:39:34 Local folder is 0 files behind and 0 files ahead of remote Starting sync at 2019-09-13 17:44:19 -0400

Sync complete.

I've only used less than 50MB of the drive space.

MStadlmeier commented 5 years ago

@Gorden-Tseng It definitely should not take this long. What's actually taking 5 minutes in your case is the retrieval of the local and remote files. So either reading your local files takes too long (unlikely with only 50MB of data) or there is some connection problem between you and your Drive. To narrow it down further, you could add the line puts Time.now before lines 83, 85 and 87 in synchronizer.rb (@local.get_files / @drive.get_files / get_diff). That way you can see which method is taking so long, although I highly suspect it's @drive.get_files.

Gorden-Tseng commented 5 years ago

@MStadlmeier You're right, it is @drive.get_files.

$ ruby drivesync.rb 2019-09-20 10:46:29 -0400 2019-09-20 10:46:29 -0400 2019-09-20 10:51:28 -0400 Local folder is 0 files behind and 0 files ahead of remote Starting sync at 2019-09-20 10:51:28 -0400

Sync complete.

Any suggestion as to what I could do?

MStadlmeier commented 5 years ago

@Gorden-Tseng Do you still have this problem? If so, does Google Drive in your browser work normally or is it slow as well?

Gorden-Tseng commented 5 years ago

@MStadlmeier I still have this problem. Google Drive on my browser works normally without any delay or issue. I'm also using Google Drive's official client on my Windows machine and it syncs immediately.

sjmik commented 4 years ago

I was able to massively speed up syncing by only getting files owned by me:

results = @service.list_files(q: "'me' in owners and not trashed", fields: fields, page_token: next_token, page_size: 300)
root@S2:~$ time ruby /opt/drivesync/drivesync.rb
Getting local files... @ 2020-05-02 01:47:47 -0400
Getting remote files... @ 2020-05-02 01:47:47 -0400
>>> Call list_files @ 2020-05-02 01:47:47 -0400
<<< Fetched 127 @ 2020-05-02 01:47:50 -0400
Counted 5 remote files in 14 folders
Calculating diff... @ 2020-05-02 01:47:50 -0400
Local folder is 0 files behind and 0 files ahead of remote
Starting sync at 2020-05-02 01:47:50 -0400
Sync complete.

real    0m4.084s
user    0m0.406s
sys     0m0.156s

Before, it was digging through the million files shared with me. (As an aside, the google drive API is a pain in the ass! Thanks for your work :smile:)

Gorden-Tseng commented 4 years ago

I was able to massively speed up syncing by only getting files owned by me:

results = @service.list_files(q: "'me' in owners and not trashed", fields: fields, page_token: next_token, page_size: 300)
root@S2:~$ time ruby /opt/drivesync/drivesync.rb
Getting local files... @ 2020-05-02 01:47:47 -0400
Getting remote files... @ 2020-05-02 01:47:47 -0400
>>> Call list_files @ 2020-05-02 01:47:47 -0400
<<< Fetched 127 @ 2020-05-02 01:47:50 -0400
Counted 5 remote files in 14 folders
Calculating diff... @ 2020-05-02 01:47:50 -0400
Local folder is 0 files behind and 0 files ahead of remote
Starting sync at 2020-05-02 01:47:50 -0400
Sync complete.

real    0m4.084s
user    0m0.406s
sys     0m0.156s

Before, it was digging through the million files shared with me. (As an aside, the google drive API is a pain in the ass! Thanks for your work 😄)

Thanks! Changing this line in drive_manager.rb solves the issue!