Skip to content

[Go] Implement Repeated Reads Solution with request-scoped caching #303

@davideme

Description

@davideme

Task

Implement POST /lamps/bulk-toggle with request-scoped caching to avoid querying the same room multiple times.

Endpoint

POST /lamps/bulk-toggle

{
  "lampIds": ["uuid1", "uuid2", "uuid3"],
  "status": true
}

Functional Requirement

Must not query the same room multiple times even if multiple lamps belong to the same room.

Implementation Hints

  • Use a map[uuid.UUID]*Room as request-scoped cache
  • Check map before querying database
  • Store fetched rooms for reuse within same request
  • Pass cache through context or as parameter

Acceptance Criteria

  • Bulk toggle updates all specified lamps
  • Room validation occurs for each lamp (room must be active)
  • Same room is only queried once per request (verify with SQL logging)
  • Returns 422 if any lamp belongs to deleted room

Parent Issue

Relates to #289

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions