{
  "code": null,
  "collection": "architecture",
  "href": "https://banes-lab.com/ontology#architecture-n-plus-one-query",
  "id": "n-plus-one-query",
  "kind": "anti-pattern",
  "layer": {
    "href": "https://banes-lab.com/ontology/schema#layer-enforcement-core",
    "json": "https://banes-lab.com/json/records/layer/enforcement-core",
    "label": "Enforcement Core",
    "markdown": "https://banes-lab.com/records/layer/enforcement-core.md",
    "ref": "layer:enforcement-core"
  },
  "name": "N Plus One Query",
  "ref": "architecture:n-plus-one-query",
  "relations": [
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-batch-fetch",
          "json": "https://banes-lab.com/json/records/lexicon/batch-fetch",
          "label": "Batch Fetch",
          "markdown": "https://banes-lab.com/records/lexicon/batch-fetch.md",
          "ref": "lexicon:batch-fetch"
        },
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-query-projection",
          "json": "https://banes-lab.com/json/records/lexicon/query-projection",
          "label": "Query Projection",
          "markdown": "https://banes-lab.com/records/lexicon/query-projection.md",
          "ref": "lexicon:query-projection"
        }
      ],
      "relation": "refactored-by"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/schema#vocabulary-severity-discouraged",
          "json": "https://banes-lab.com/json/records/vocabulary/severity-discouraged",
          "label": "discouraged",
          "markdown": "https://banes-lab.com/records/vocabulary/severity-discouraged.md",
          "ref": "vocabulary:severity-discouraged"
        }
      ],
      "relation": "severity"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-category-anti-patterns",
          "json": "https://banes-lab.com/json/records/architecture-category/anti-patterns",
          "label": "Anti-patterns",
          "markdown": "https://banes-lab.com/records/architecture-category/anti-patterns.md",
          "ref": "architecture-category:anti-patterns"
        }
      ],
      "relation": "category"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/schema#force-architecture-evolution",
          "json": "https://banes-lab.com/json/records/force/architecture-evolution",
          "label": "Architecture evolution",
          "markdown": "https://banes-lab.com/records/force/architecture-evolution.md",
          "ref": "force:architecture-evolution"
        }
      ],
      "relation": "force"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-algorithmic-efficiency",
          "json": "https://banes-lab.com/json/records/architecture/algorithmic-efficiency",
          "label": "Algorithmic Efficiency",
          "markdown": "https://banes-lab.com/records/architecture/algorithmic-efficiency.md",
          "ref": "architecture:algorithmic-efficiency"
        }
      ],
      "relation": "negated-by"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-category-anti-patterns",
          "json": "https://banes-lab.com/json/ontology/principles/architecture-category-anti-patterns",
          "label": "Anti-patterns",
          "markdown": "https://banes-lab.com/ontology/principles/architecture-category-anti-patterns.md",
          "ref": "chapter:/ontology#architecture-category-anti-patterns"
        },
        {
          "href": "https://banes-lab.com/ontology#architecture-category-scalability-performance-optimization",
          "json": "https://banes-lab.com/json/ontology/principles/architecture-category-scalability-performance-optimization",
          "label": "Scalability / Performance / Optimization",
          "markdown": "https://banes-lab.com/ontology/principles/architecture-category-scalability-performance-optimization.md",
          "ref": "chapter:/ontology#architecture-category-scalability-performance-optimization"
        },
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-category-event-messaging-async",
          "json": "https://banes-lab.com/json/ontology/lexicon/lexicon-category-event-messaging-async",
          "label": "Event Messaging Async",
          "markdown": "https://banes-lab.com/ontology/lexicon/lexicon-category-event-messaging-async.md",
          "ref": "chapter:/ontology/lexicon#lexicon-category-event-messaging-async"
        },
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-category-scalability-performance-optimization",
          "json": "https://banes-lab.com/json/ontology/lexicon/lexicon-category-scalability-performance-optimization",
          "label": "Scalability / Performance / Optimization",
          "markdown": "https://banes-lab.com/ontology/lexicon/lexicon-category-scalability-performance-optimization.md",
          "ref": "chapter:/ontology/lexicon#lexicon-category-scalability-performance-optimization"
        },
        {
          "href": "https://banes-lab.com/ontology/schema#the-vocabulary-severity",
          "json": "https://banes-lab.com/json/ontology/schema/the-vocabulary-severity",
          "label": "Severity levels",
          "markdown": "https://banes-lab.com/ontology/schema/the-vocabulary-severity.md",
          "ref": "chapter:/ontology/schema#the-vocabulary-severity"
        },
        {
          "href": "https://banes-lab.com/ontology/schema#the-forces",
          "json": "https://banes-lab.com/json/ontology/schema/the-forces",
          "label": "The forces",
          "markdown": "https://banes-lab.com/ontology/schema/the-forces.md",
          "ref": "chapter:/ontology/schema#the-forces"
        }
      ],
      "relation": "linked-from"
    }
  ],
  "summary": "A defect in which a collection is fetched and then one further query is issued per item.",
  "siblings": {
    "next": {
      "href": "https://banes-lab.com/ontology#architecture-cache-poisoning-by-design",
      "json": "https://banes-lab.com/json/records/architecture/cache-poisoning-by-design",
      "label": "Cache Poisoning by Design",
      "markdown": "https://banes-lab.com/records/architecture/cache-poisoning-by-design.md",
      "ref": "architecture:cache-poisoning-by-design"
    },
    "previous": {
      "href": "https://banes-lab.com/ontology#architecture-chatty-interface",
      "json": "https://banes-lab.com/json/records/architecture/chatty-interface",
      "label": "Chatty Interface",
      "markdown": "https://banes-lab.com/records/architecture/chatty-interface.md",
      "ref": "architecture:chatty-interface"
    }
  },
  "up": {
    "href": null,
    "json": "https://banes-lab.com/json/api/records/architecture",
    "label": "Architecture principles",
    "markdown": "https://banes-lab.com/api/records/architecture.md",
    "ref": "api:records/architecture"
  },
  "aliases": [
    "N+1 Query"
  ],
  "exemplar": {
    "after": "const foos = await fooStore.all();\nconst bars = await barStore.findMany(foos.map(f => f.barId));",
    "before": "const foos = await fooStore.all();\nfor (const foo of foos) foo.bar = await barStore.find(foo.barId);",
    "lang": "ts",
    "medium": "code"
  },
  "formedBy": "Fetch a collection, then issue one query or remote call per item rather than fetching required related data intentionally.",
  "scope": [
    "architecture_evolution"
  ],
  "severity": "discouraged"
}
