Skip to content

Linear-Scale Performance Bottleneck (Inefficient Validation) #3

@codeCraft-Ritik

Description

@codeCraft-Ritik

This issue is present in the backend validation of the Inventory-app and the frontend data management of Kollege.

The Problem in Inventory-app:
The validateBook middleware in controllers/booksController.js attempts to ensure ISBN and Title uniqueness by fetching every single book from the database into server memory using booksQueries.getAllBooks(). It then iterates through the entire list in JavaScript to check for duplicates.

The Problem in Kollege:
In src/Components/Queries/Attendance.js, the fetchAttendance function fetches a list of students and manually iterates through them to inject properties like present: true using a loop that mutates the objects directly.

The Technical Detail:
These operations have O(n) complexity, meaning the time and memory required grow linearly with the number of records. As the database size increases from a few items to thousands, these checks will cause significant latency, high memory usage, and potential server crashes during routine validation.

The Fix:
Leverage database indexing by using targeted queries such as SELECT 1 FROM books WHERE isbn = $1 LIMIT 1. This allows the database to perform a nearly instant lookup regardless of the total number of records, significantly improving performance and scalability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions