trilbymedia / grav-plugin-git-sync

Collaboratively Synchronize your Grav `user` folder hosted on GitHub, BitBucket or GitLab
Apache License 2.0
243 stars 58 forks source link

Saving a page becomes slow when enabling plugin. #51

Closed karfau closed 6 years ago

karfau commented 7 years ago

Everything works fine in my configuration, but saving a page takes "forever" when the plugin is enabled vs. when I disable it.
I assume this is because the plugin waits for the git command to finish, before responding.

Is it possible to change something (configuration wise, or by modifying the plugin) to let git do its thing and already respond with the page anyway after it si stored locally?

I'm also thinking about adding a button somewhere to allow the user to store his work when done, instead of on every change, but I couldn't find an option for this either.

Any Ideas welcome, I'm willing to contribute back to the plugin.

Best Christian

OleVik commented 7 years ago

On saving: This is because the plugin has to phone the repo. It could be possibly to separate the logic so that saving does a regular filesystem-write of the file, and a background-task handles updating Git. This requires some functionality for performing this in the background, though, which might be tricky to handle robustly.

On storing temporarily: I'm unaware of whether this has made it into Admin, but its been suggested to leverage LocalStorage in the browser to auto-save changes - and of course indicate this with a "Last stored X mins ago" - to allow easier editing without saving. The mechanism has very good cross-browser support now, and is reliable unless the user clears their cache, which would allow writing without saving.

karfau commented 7 years ago

In the mean time I added an hourly cronjob calling bin/plugin git-sync sync.

But I can imagine it can be valuable to have options for the following:

  1. Only commit when saving a file
  2. Indicate unpushed changes as a number or just a symbol beside number of pages (like when plugins have updates). For this there should also be an option for the user to do the sync to get rid of the symbol/number.

What do you guys think about this approach?

w00fz commented 7 years ago

I was waiting for admin to include an actions area for the sidebar where 3rd party plugins can create their actions that are always available. With that approach I wanted to make the sync on save optional so that the user could manually sync from the sidebar at wish.

The action bar is something @rhukster and I discussed a while back and the slow saving of gitsync is what inspired it.

karfau commented 7 years ago

Cool, just say a word if there is anything I can help with.

AmauryCarrade commented 6 years ago

I was waiting for admin to include an actions area for the sidebar where 3rd party plugins can create their actions that are always available. With that approach I wanted to make the sync on save optional so that the user could manually sync from the sidebar at wish.

Hi! Now that this is possible (and even implemented on GitSync side), any updates? I would be interested (and I can do it myself and open a PR if you want). I love this plugin, but I'm a little bit sick of the loading time when I save a page…

paulhibbitts commented 6 years ago

Hi @AmauryCarrade , I am experimenting with some minor customizations to the Git Sync blueprint and PHP files to provide an option to disable page-saves and only sync manually. You can see this in action if you download my newest Open Matter Course Hub skeleton at https://getgrav.org/downloads/skeletons

Customized blueprint file: https://gist.github.com/paulhibbitts/8e4a2c330d2fbc3ac82225be33ac6c3e

Customized PHP file: https://gist.github.com/paulhibbitts/5517ea998ba149754dfc7340fa1616fc

Hope the above might be of help to you too.

AmauryCarrade commented 6 years ago

Sounds great! By looking at the code, I was to submit a PR somewhat like your code (with a few differences like disabling sync for all CRUD operations, not only saves). I could use your code as a base to spare me some time, if you're okay with that :)

paulhibbitts commented 6 years ago

Thanks for the PR!

AmauryCarrade commented 6 years ago

I submitted the PR, do what you want with it :p

paulhibbitts commented 6 years ago

Hi @AmauryCarrade , thanks again for your helpful PR. As a first step I've included your PR code (with a few minor UI text tweaks) in my newest Open Course Hub skeleton https://getgrav.org/downloads/skeletons Please take a look-see and let me know what you think.

https://github.com/paulhibbitts/grav-skeleton-plugin-customizations/tree/master/grav-skeleton-course-hub/git-sync