From cd6eebb226c8261793d1fa0a061db32ecbea8705 Mon Sep 17 00:00:00 2001
From: Yaeli Gimelshtein <yaelig@getport.io>
Date: Tue, 21 Jan 2025 07:56:46 -0800
Subject: [PATCH] [Core] Fixed query to make the search easier on port's side
 (#1338)

# Description

What - improvements to reduce port's load

Why - to make the query easier for port

How - added blueprint to the search query

## Type of change

Please leave one option from the following and delete the rest:

- [ ] New feature (non-breaking change which adds functionality)



### Core testing checklist

- [ ] Integration able to create all default resources from scratch
- [ ] Resync finishes successfully
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] Scheduled resync able to abort existing resync and start a new one
- [ ] Tested with at least 2 integrations from scratch
- [ ] Tested with Kafka and Polling event listeners
- [ ] Tested deletion of entities that don't pass the selector
---
 CHANGELOG.md                                    |  6 ++++++
 port_ocean/core/integrations/mixins/sync_raw.py | 10 +++++++---
 pyproject.toml                                  |  2 +-
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbab34b864..b4e2edcd3e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 <!-- towncrier release notes start -->
+## 0.18.1 (2025-01-21)
+
+### Improvements
+
+- Updated the search entitites query sent to port with blueprint
+
 ## 0.18.0 (2025-01-15)
 
 ### Improvements
diff --git a/port_ocean/core/integrations/mixins/sync_raw.py b/port_ocean/core/integrations/mixins/sync_raw.py
index 4583c740cd..4f3f65c8cd 100644
--- a/port_ocean/core/integrations/mixins/sync_raw.py
+++ b/port_ocean/core/integrations/mixins/sync_raw.py
@@ -137,7 +137,7 @@ def _construct_search_query_for_entities(self, entities: list[Entity]) -> dict:
             entities (list[Entity]): List of entities to search for.
 
         Returns:
-            dict: Query structure for searching entities by identifier.
+            dict: Query structure for searching entities by identifier and blueprint.
         """
         return {
             "combinator": "and",
@@ -147,10 +147,14 @@ def _construct_search_query_for_entities(self, entities: list[Entity]) -> dict:
                     "rules": [
                         {
                             "property": "$identifier",
+                            "operator": "in",
+                            "value": [entity.identifier for entity in entities],
+                        },
+                        {
+                            "property": "$blueprint",
                             "operator": "=",
-                            "value": entity.identifier,
+                            "value": entities[0].blueprint,
                         }
-                        for entity in entities
                     ]
                 }
             ]
diff --git a/pyproject.toml b/pyproject.toml
index ce30986271..56f0cd06cf 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "port-ocean"
-version = "0.18.0"
+version = "0.18.1"
 description = "Port Ocean is a CLI tool for managing your Port projects."
 readme = "README.md"
 homepage = "https://app.getport.io"