summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-02-20 10:17:13 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-02-20 10:17:13 +0700
commit7394cd71c05d56ebfd5a5f95518a849289a782e0 (patch)
tree9ed12cbed0b52950a5fb7eca45295ee423910886
parentb468da04ba901590b764694bfdd47366bc649dab (diff)
<Miqdad> fix not sync to solr when there is no products
-rw-r--r--indoteknik_custom/models/keywords.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/indoteknik_custom/models/keywords.py b/indoteknik_custom/models/keywords.py
index 4ab649dc..9c8e2cfd 100644
--- a/indoteknik_custom/models/keywords.py
+++ b/indoteknik_custom/models/keywords.py
@@ -133,7 +133,7 @@ class Keywords(models.Model):
def _onchange_solr_flag(self):
"""Set solr_flag=2 when tracked fields change to trigger queue sync"""
for record in self:
- if not record.skip:
+ if not record.skip and len(record.product_ids) > 0:
record.solr_flag = 2
def solr_flag_to_queue(self, limit=500):
@@ -164,6 +164,11 @@ class Keywords(models.Model):
"""Callback method executed by apache.solr.queue - syncs keyword data to Solr"""
documents = []
for keyword in self:
+ # Skip syncing if product count is 0
+ if len(keyword.product_ids) == 0:
+ _logger.info('Skipping Solr sync for keyword "%s" - no products found', keyword.keywords)
+ continue
+
searchkey = (keyword.keywords or '').strip().lower().replace(' ', '-')
try:
doc = {
@@ -194,6 +199,11 @@ class Keywords(models.Model):
documents = []
for keyword in keywords:
+ # Skip syncing if product count is 0
+ if len(keyword.product_ids) == 0:
+ _logger.info('Skipping Solr sync for keyword "%s" - no products found', keyword.keywords)
+ continue
+
searchkey = (keyword.keywords or '').strip().lower().replace(' ', '-')
try:
doc = {
@@ -227,6 +237,8 @@ class Keywords(models.Model):
neded_sync = any(field in vals for field in tracked_fields)
if neded_sync and self.skip == False:
for record in self:
- record.solr_flag = 2
+ # Only flag for sync if there are products
+ if len(record.product_ids) > 0:
+ record.solr_flag = 2
return result