ztjhz / BetterChatGPT

An amazing UI for OpenAI's ChatGPT (Website + Windows + MacOS + Linux)
http://bettergpt.chat/
Creative Commons Zero v1.0 Universal
7.8k stars 2.63k forks source link

Replace localStorage with IndexedDB (Dexie) for storing chats #591

Open zewebdev1337 opened 3 weeks ago

zewebdev1337 commented 3 weeks ago

The current implementation uses localStorage which comes with a set of limitations and flaws that might become apparent for long-time/intensive users of this app.

See #588, #566, #536

The main 3 issues that I personally have encountered are:

My suggestion is to implement chat storage using Dexie.js (IndexedDB wrapper). This is a more fit solution to storing the large strings of text contained in chats while using localStorage to save the settings, key, etc.

This will avoid running out of storage in localStorage, and it can be written to from multiple tabs simultaneously without interferences between them; allowing for multiple tabs to be used at once without the issues that come with doing this in the current version of the app.

By using the BroadcastChannel API, changes to the DB made by other tabs are reflected instantly in all open tabs. It seems like the components involved need to implement logic to be re-rendered when data affecting them changes.

I don't know if this is the best solution to this issue given the size of the codebase is nearing 10,000 lines and my experience with a project using a Dexie.js DB and featuring updates in real time for all tabs accessing it, is limited to small, much simpler projects.

I can contribute to this feature but would like confirmation from the maintainer as my last contribution was never approved, rejected, or acknowledged, so I'm reluctant to start working on such a big refactor if there's no chance for it to be merged to upstream.

Input from other users/coders would be extremely valuable since this is only one possible solution and someone else might have a better or more solid plan to tackle this issue.