ajaynegi45 / LibraryMan-API

Revolutionize book management with LibraryMan! Easily track stock, borrowers, and due dates, streamlining operations for schools, companies, and libraries worldwide, ensuring efficient and organized book lending.
MIT License
44 stars 51 forks source link

[IMPROVEMENT] Improve the Send Reminder Notifications 2 Days Before Book Due Date Feature #58

Open ajaynegi45 opened 1 month ago

ajaynegi45 commented 1 month ago

Is this feature already requested?

Problem or Missing Functionality

The system currently sends reminder notifications 2 days before the book's due date by querying the database on daily basis to check for due books. This process may involve daily database queries, which can lead to performance inefficiencies.

Improvement Request

  1. Optimize Database Queries:

    • Reduce the number of queries being made to the database while fetching due books for sending reminders.
  2. Performance Enhancement:

    • Analyze the existing workflow to identify potential bottlenecks.
    • Implement improvements that reduce the overall time taken to send reminders and the resource usage.
  3. Documentation:

    • Document the optimized solution clearly for future developers.
    • Include details about the new logic, optimized query flow, and how it impacts performance.

Expected Outcome

7vk commented 1 month ago

Hey @ajaynegi45 I’d love to try my hands on this issue and see how I can contribute. Could you assign it to me? Looking forward to working on it!

ajaynegi45 commented 1 month ago

Hey @ajaynegi45 I’d love to try my hands on this issue and see how I can contribute. Could you assign it to me? Looking forward to working on it!

Hey @7vk,

Thanks for showing interest in tackling this issue! I'd be happy to assign it to you, but before I do, could you walk me through how you plan to implement this feature in detail?

Also, before jumping in, I recommend giving the Readme.md a thorough read. It'll help you get a solid grasp of the project's goals and purpose. Plus, check out the Contributing.md file for some handy guidelines that’ll make your contribution process smoother, especially if you're new around here.

If you run into any questions or need help along the way, don’t hesitate to reach out!

7vk commented 1 month ago

I suggest we create a separate entity to schedule reminders which would schedule the reminders when the book is borrowed. So instead of scanning all borrowings daily, we query the specific reminders that are due.

What do you think about this approach? your guidance would be much appreciated.

ajaynegi45 commented 1 month ago

I suggest we create a separate entity to schedule reminders which would schedule the reminders when the book is borrowed. So instead of scanning all borrowings daily, we query the specific reminders that are due.

What do you think about this approach? your guidance would be much appreciated.

Thank you for your suggestion, @7vk!
I really appreciate your input on creating a separate entity for scheduling reminders. It's a clever approach that could indeed optimize the system. Here are a few additional considerations and suggestions that might further enhance this solution:

Benefits of a Separate Reminder Entity

1. Reduced Database Load

By introducing a separate entity for scheduling reminders, we can avoid the need for daily scans of all borrowings, significantly cutting down the number of queries and reducing the strain on the database. Instead, we could query only the reminders that are due, leading to a more efficient process.

2. Improved Performance

This approach could make the system more scalable and performant, especially when handling a large volume of users and borrowings. Fewer and more targeted queries should result in noticeable improvements in speed and resource usage during the reminder process.


Edge Cases to Consider

To ensure the robustness of this approach, we’ll need to manage certain key edge cases effectively:

1. Book Renewals or Due Date Changes

If a user renews a book or if the due date changes for any reason, we need to ensure that the associated reminder is also updated. Failing to do so could result in sending incorrect reminders.

Solution:
Implement an event-driven system or listener that triggers updates to the reminder entity whenever a borrowed book’s due date is modified.

2. Book Returns Before the Due Date

If a user returns a book early, the corresponding reminder should be removed from the system to avoid sending unnecessary notifications.

Solution:
On book return, either soft-delete or remove the scheduled reminder entity. Optionally, you can archive reminders for reporting purposes, but they should no longer be active.


Additional Feature: Fine Calculation & Overdue Notifications

1. Daily Notifications After Due Date Passes

Once the due date for a book passes, the system should automatically send daily notifications to the user, reminding them that the due date has passed and that a fine of Rs. 10 per day is accruing. This notification should also display the current fine amount until the book is returned.

Solution:
After the due date passes, we’ll trigger a daily reminder until the book is returned. This can be optimized by calculating the fine dynamically based on the number of days overdue, rather than updating the fine amount in the database every day.

To avoid performance bottlenecks, we can batch-process overdue reminders in off-peak hours, sending notifications and calculating fines for all overdue books at once, ensuring that the process remains scalable even with a large user base.


Next Steps

I've assigned this issue to you and I'm confident that your approach will make the system more optimized, faster, and scalable. Be sure to document your code thoroughly using Javadoc comments to ensure clarity and maintainability. Feel free to reach out if you have any questions or need assistance as you proceed.

Looking forward to seeing your implementation!

7vk commented 1 month ago

@ajaynegi45 I'll get it done. If I need help with anything I'll reach out.