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

[FIX]: Unnecessary Logs, Preventing System Inefficiencies and Inefficient Retries While Populating Dashboard Database #6078

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

JiyaGupta-cs
Copy link
Contributor

@JiyaGupta-cs JiyaGupta-cs commented Dec 29, 2024

Issue Overview

When running the rake populate:dev task, the system was encountering a ActiveRecord::RecordNotUnique error due to duplicate entries in the campaigns_courses table. This error led to the creation of excessive logs, making it difficult to analyze system behavior and troubleshoot issues efficiently.

Additionally, if a duplicate record is encountered for one entry during the execution of the populate_dashboard task, the process halts further attempts to populate subsequent entries. This causes the database to remain partially populated, failing to insert other valid records.

The presence of a single pre-existing record in the database could arise if the user terminates the populate:dev command prematurely. This interruption might happen because the process takes too long to fetch and insert data, leading to an incomplete population of demo records.

Closes #6079

Proposed Solution

To address the issues with the populate:dev task and ensure a smoother data population process, the following solutions were implemented:

  1. Handle Duplicate Records Gracefully:
    Adjusted the logic to check for existing entries before creating new records. This prevents duplicate records from causing the process to fail with ActiveRecord::RecordNotUnique errors.

  2. Continue Processing After Errors:
    Introduced exception handling to ensure that encountering an error (e.g., a duplicate record) does not stop the task. Instead, the task skips the problematic entry and continues processing subsequent entries, ensuring the database is populated with all valid records.

  3. Avoid Redundant Associations:
    Added checks to avoid re-associating courses that already exist in a campaign, eliminating unnecessary database operations and log noise.

  4. Improved Logging and Error Reporting:
    Enhanced logging to provide clear, actionable error messages when issues arise, improving the debugging experience.

Changes Made

  1. Duplicate Record Prevention:
  • Introduced a conditional check in the make_copy_of function to verify the existence of records (e.g., courses, users, wikis) before attempting to create them.
  1. Graceful Error Handling:
  • Wrapped key operations in begin-rescue blocks to catch and log errors like ActiveRecord::RecordInvalid and other unexpected issues.
  • Skips problematic entries instead of halting the entire process, ensuring subsequent entries are processed.
  1. Optimized Campaign Association:
  • Before associating a course with a campaign, the code checks if the course is already part of the campaign, avoiding redundant operations.
  1. Logging Improvements:
    Added detailed error and progress messages using Rails.logger and puts to provide better visibility into the task execution.

  2. Database Population Flow:

  • Ensured all related data, such as users, assignments, and wikis, are fetched and created efficiently.
  • Avoided re-adding the home wiki when processing related wikis.

Screenshots -

Before -

image

After -

image

…ient Retries while populating the dashboard database
@ragesoss ragesoss merged commit 42bc73f into WikiEducationFoundation:master Dec 30, 2024
1 check passed
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.

Inefficient Handling of Duplicate Records in rake populate:dev Task
2 participants