gristlabs / grist-core

Grist is the evolution of spreadsheets.
https://www.getgrist.com/
Apache License 2.0
7.14k stars 319 forks source link

(Automatically) (re)load external changes to SQLite database #836

Open mpsijm opened 8 months ago

mpsijm commented 8 months ago

I was experimenting a bit with accessing a .grist SQLite database via the sqlite3 program. Super awesome that it's possible to change data externally like this! However, I needed to restart Grist in order for the changes to become visible.

My setup:

To reproduce:

Initially, nothing happens in Grist. However, after restarting Grist, the new row is shown. For this new row, the formula columns initially remain empty, but are updated within a few seconds, so that's really nice! However, it would be cool if Grist could reload external changes without a restart, either automatically or by adding a "reload database" button somewhere. Moving back to home and reopening the file didn't do the trick.

wunter8 commented 8 months ago

There is an API endpoint to force the document to reload: /api/docs/:docId/force-reload

I haven't tested it myself, but I think if you edit the file with sqlite3 and hit that endpoint (e.g., with curl), it will reload the document in the browser for any users currently looking at it

I don't know if this will cause any other side effects, though. I think that endpoint is undocumented. I only know about it because I've seen it discussed in other Github issues

mpsijm commented 8 months ago

Thanks for the pointer! I tried POSTing to that endpoint with an empty body, as suggested by @paulfitz here, but unfortunately, that did not refresh the page in my Electron app. The OP of that thread suggest that this does work with the "Self-Managed Core" setup, which I will test later, since that's how I'd intend to use this anyway :slightly_smiling_face: EDIT: never mind, I used the wrong document ID in my API call, and this actually works! :smile:

Armed with a new search query "Grist force-reload", I also found this thread, which suggests clicking a skull icon in the settings page of the document, but I don't see this setting (potentially because I'm running from Electron).

EDIT: So, I now have something that works for me, but perhaps it would be nice to also have some way to force reload the Electron app from the UI. If you think that this doesn't belong on Grist's roadmap, feel free to close this issue, because my question has been answered :slightly_smiling_face: