Skip to content

Remove redundant shelf lookup (double DB hit) #307

@leodvincci

Description

@leodvincci

Remove redundant shelf lookup (double DB hit)

Type: Performance / Refactor
Priority: P2

Summary

findShelfById() and isFull() each load shelf separately.

Impact

Extra round-trip; worse if shelf becomes remote.

Evidence

bookCommandUseCases.java lines 28 and 33.

if (!shelfAccessPort.findShelfById(shelfAssignmentRequest.shelfId()).isPresent()) {
  throw new IllegalStateException(
      "Shelf not found with id: " + shelfAssignmentRequest.shelfId());
}

if (shelfAccessPort.isFull(shelfAssignmentRequest.shelfId())) {
  throw new IllegalStateException(
      "Shelf with id " + shelfAssignmentRequest.shelfId() + " is full");
}

Proposed Fix

Consolidate into single validation call or reuse loaded shelf data.

Acceptance Criteria

  • Only one shelf query per placement.

Expected

Shelf validation performs one lookup per placement (or single remote call).

Actual

Shelf is loaded twice: once for findShelfById(), again for isFull().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions