Skip to content

N+1 queries in AssociateTagsWithRecipe #51

@windoze95

Description

@windoze95

Summary

In internal/service/recipe.go:243-270, AssociateTagsWithRecipe executes a separate FindTagByName query for each hashtag extracted from a recipe. For a recipe with N tags, this produces N individual SELECT queries plus up to N individual INSERT queries.

Impact

Under load, recipes with many hashtags can generate dozens of sequential DB round-trips at generation time, increasing latency and DB load.

Suggested Fix

Batch-load existing tags with a single query:

SELECT * FROM tags WHERE hashtag IN (...)

Identify which tags are missing, then create them in a single batch insert. Associate all tags to the recipe in one INSERT ... ON CONFLICT DO NOTHING or equivalent batch operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions