From 91746f243c614f091fe89ffc6eb5e2d61717ee32 Mon Sep 17 00:00:00 2001
From: Eileen McNaughton <emcnaughton@wikimedia.org>
Date: Wed, 2 Mar 2022 16:56:17 +1300
Subject: [PATCH] Only acl line items based on contribution

The query becomes insane if we allow membership, participant ids to bubble up here
---
 CRM/Price/BAO/LineItem.php | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php
index 22a420297892..8251e1276017 100644
--- a/CRM/Price/BAO/LineItem.php
+++ b/CRM/Price/BAO/LineItem.php
@@ -1268,4 +1268,19 @@ public static function entityTables(): array {
     ];
   }
 
+  /**
+   * Add contribution id select where.
+   *
+   * This overrides the parent to PREVENT additional entity_id based
+   * clauses being added. Additional filters joining on the participant
+   * and membership tables just seem too non-performant.
+   *
+   * @inheritDoc
+   */
+  public function addSelectWhereClause(): array {
+    $clauses['contribution_id'] = CRM_Utils_SQL::mergeSubquery('Contribution');
+    CRM_Utils_Hook::selectWhereClause($this, $clauses);
+    return $clauses;
+  }
+
 }