Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add indexDB #5324

Merged
merged 5 commits into from
Aug 27, 2024
Merged

Conversation

Dogtiti
Copy link
Member

@Dogtiti Dogtiti commented Aug 26, 2024

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

Summary by CodeRabbit

  • New Features

    • Introduced a robust state management solution using IndexedDB with fallback to localStorage for enhanced data handling.
    • Added new asynchronous methods for managing state: getItem, setItem, removeItem, and clear.
    • Enhanced persistence capabilities in the state management store to improve performance.
    • Improved control flow for clearing chat data with an asynchronous clearAllData method.
  • Dependencies

    • Added idb-keyval dependency for improved interaction with IndexedDB.

@Dogtiti Dogtiti requested a review from lloydzhou August 26, 2024 13:14
Copy link

vercel bot commented Aug 26, 2024

@Dogtiti is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Aug 26, 2024

Walkthrough

The changes introduce a new IndexDBStorage class for state management using IndexedDB, with a fallback to localStorage. The createPersistStore function in store.ts has been updated to utilize this new storage mechanism. Additionally, the idb-keyval library has been added as a dependency to facilitate interaction with IndexedDB, enhancing data persistence capabilities across the application. The clearAllData method in the chat store has also been made asynchronous.

Changes

Files Change Summary
app/utils/indexDB-storage.ts, app/utils/store.ts Introduced IndexDBStorage class for managing state storage with IndexedDB and localStorage fallback. Updated createPersistStore to use createJSONStorage with indexDBStorage.
app/store/chat.ts Modified clearAllData method to be asynchronous, ensuring proper handling of IndexedDB operations before clearing local storage. Added import for indexedDBStorage.
package.json Added idb-keyval dependency to enhance IndexedDB interaction capabilities.

Poem

In a world of data, hopping so free,
A new storage method, oh what glee!
With IndexedDB's might, and local's embrace,
Our state now dances, in a cozy space.
So here's to the changes, a joyful cheer,
For a rabbit's delight, we hold dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Your build has completed!

Preview deployment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 718782f and 4060e36.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (3)
  • app/utils/indexDB-storage.ts (1 hunks)
  • app/utils/store.ts (2 hunks)
  • package.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
Additional context used
Biome
app/utils/indexDB-storage.ts

[error] 5-5: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

Additional comments not posted (5)
app/utils/indexDB-storage.ts (3)

7-9: Ensure fallback consistency.

The getItem method retrieves an item from IndexedDB or falls back to localStorage. Ensure that both storages are always in sync to avoid inconsistencies.

Verify that the fallback mechanism does not lead to inconsistencies between IndexedDB and localStorage.


11-13: LGTM!

The setItem method is correctly implemented.

The code changes are approved.


15-17: LGTM!

The removeItem method is correctly implemented.

The code changes are approved.

app/utils/store.ts (2)

2-2: LGTM!

The import statement has been correctly updated to include createJSONStorage.

The code changes are approved.


35-35: LGTM!

The persistOptions.storage is correctly assigned to createJSONStorage(() => indexDBStorage).

The code changes are approved.

app/utils/indexDB-storage.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4060e36 and 492b55c.

Files selected for processing (1)
  • app/store/chat.ts (2 hunks)
Additional comments not posted (1)
app/store/chat.ts (1)

669-672: LGTM!

The function is correctly implemented and ensures that IndexedDB is cleared before clearing local storage and reloading the page, preventing potential data inconsistencies.

The code changes are approved.

app/utils/indexDB-storage.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 492b55c and c2fc0b4.

Files selected for processing (2)
  • app/store/chat.ts (2 hunks)
  • app/utils/indexedDB-storage.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/store/chat.ts

app/utils/indexedDB-storage.ts Show resolved Hide resolved
app/utils/indexedDB-storage.ts Show resolved Hide resolved
app/utils/indexedDB-storage.ts Show resolved Hide resolved
app/utils/indexedDB-storage.ts Show resolved Hide resolved
app/utils/indexedDB-storage.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c2fc0b4 and 7b6fe66.

Files selected for processing (1)
  • app/utils/store.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/utils/store.ts

@lloydzhou lloydzhou merged commit b6bb167 into ChatGPTNextWeb:main Aug 27, 2024
1 of 2 checks passed
@laxfer
Copy link

laxfer commented Sep 3, 2024

用你这个代码后,有严重bug,聊天对话页面刷新三次,聊天内容就没了,被重置了

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


After using your code, there is a serious bug. The chat conversation page is refreshed three times, and the chat content is gone and reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants