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

Optimize Offline Mode for Create, Update, and Delete Operations #21

Merged
merged 5 commits into from
Dec 18, 2024

Conversation

neozhu
Copy link
Owner

@neozhu neozhu commented Dec 17, 2024

Title: Optimize Offline Mode for Create, Update, and Delete Operations

Description:

This PR improves offline mode handling for Create, Update, and Delete operations by ensuring seamless user experience and data consistency when the application is offline. Key updates include:

  1. Offline Create:

    • Product creation commands are now cached in IndexedDB.
    • Created products are stored locally and immediately added to the product list (pagination cache).
    • Ensures users can create products offline with no disruption.
  2. Offline Update:

    • Update commands are cached and applied locally to both product data and pagination cache.
    • Local products reflect the updates immediately while offline.
    • Commands are stored to synchronize with the server once online.
  3. Offline Delete:

    • Delete commands are cached in IndexedDB for later execution.
    • Products targeted for deletion are immediately removed from:
      • Individual product cache.
      • Paginated product lists.
    • Prevents display of stale data in the offline product list.
  4. Data Synchronization:

    • All offline commands for Create, Update, and Delete are stored separately for accurate replay.
    • Synchronization logic will ensure commands are executed in order when connectivity is restored.
  5. Code Refactoring:

    • Optimized IndexedDB operations for readability, maintainability, and performance.
    • Centralized caching methods for offline operations.

Why It’s Needed:

This PR ensures robust offline support for CRUD operations in applications. Users can seamlessly interact with the system, whether online or offline, with automatic data synchronization when they reconnect.


Changes Made:

  1. Create:

    • Cached create commands in IndexedDB.
    • Added new products to the local cache and updated paginated results.
  2. Update:

    • Cached update commands and applied changes locally to product details and pagination.
  3. Delete:

    • Cached delete commands.
    • Removed products from the local cache and updated pagination to reflect the deletions.
  4. Synchronization:

    • Structured offline commands for replay (Create, Update, Delete).
  5. Refactoring:

    • Improved data handling in IndexedDB.
    • Centralized logic for CRUD caching and local updates.

@neozhu neozhu merged commit 64042ff into main Dec 18, 2024
5 checks passed
@neozhu neozhu deleted the improve/offlinemode branch December 18, 2024 01:21
@Hadi69ans
Copy link

Hadi69ans commented Jan 4, 2025

It sounds great, but this system is only suitable for single-user systems that sometimes have problems connecting to the Internet, but it seems to need improvement in integrated systems. For example, if the system is connected to an online store, the store inventory or product prices are displayed correctly for the user, but this may not be the case for customers who request a purchase.
I think you need to change your perspective on this and consider a more comprehensive situation. For example, in the integrated system you have created, each tenant should also have an offline database, the reduced version of which is on each tenant's internal network so that the employees of that tenant can work offline and at high speed within their system. . The system and at the same time the information enters the online system in the shortest possible time so that they do not have problems in case of an outage and can continue working at any moment. And at the same time their online sales or trading system is also in the most up-to-date state possible.
I think this method meets more needs and is in greater demand.

@neozhu
Copy link
Owner Author

neozhu commented Jan 4, 2025

Hi, thank you for your feedback!

Currently, our offline mode relies on IndexedDB to temporarily store data. This is still an experimental feature and is under continuous improvement. As for your suggestion about “each tenant having an online database,” I’m not entirely sure what you mean. How would users access an online database while in offline mode? I’d appreciate it if you could clarify this point.

Additionally, I’ve noticed that with Blazor WPA, once installed as a local app, it cannot be opened if the client host is offline. This indeed makes the offline mode less meaningful. We’ll further evaluate its practicality and explore potential improvements.

Looking forward to more discussions and your suggestions!

@Hadi69ans
Copy link

Yes, I agree with what you have done. I think it is very good to eliminate the bad feeling of not being able to access the online system at times and temporary outages so that the user does not feel disconnected and reconnected.
But I thought that the offline mode system is a system that works on a shared local area network between multiple systems in a company without internet access, which also has the ability to switch to an online system in a fraction of a second.
For example, a company or a shopping mall has an internal local area network that includes 10 POS systems for sellers, an administrator user system, an accountant user system, etc., which use an internal server and all employees use it simultaneously and on that server. Synchronization with it
And high speed, whether one user uses the system or 100 users in the workplace, all users can work with the system simultaneously and with a single data. Now, if this company intends to provide services or products online through a website, etc., where there is the least possible difference between the company's internal information and the store, and if there is internet, the information is updated quickly. It is possible. ? What should it do to have both the speed and efficiency of the local network and the up-to-date information of the online website? Should we use two synchronized databases or is the method you mentioned useful for this?

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.

2 participants