summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-09-13 08:56:27 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-09-13 08:56:27 +0700
commit8cd5ba78d36ebb399a69e87aa2bdd76b01bf5504 (patch)
tree5eab492373a621b5ae1a12545528321ee3cd8d60
parent9715888978cb93586f62ddb7ea153d0504bd290d (diff)
Create solr commit collections scheduler
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rw-r--r--indoteknik_custom/models/solr/apache_solr.py4
-rw-r--r--indoteknik_custom/models/solr/product_product.py7
-rw-r--r--indoteknik_custom/models/solr/product_public_category.py1
-rw-r--r--indoteknik_custom/models/solr/product_template.py9
-rw-r--r--indoteknik_custom/views/apache_solr.xml16
6 files changed, 27 insertions, 11 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index e1be8910..55708acc 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -92,6 +92,7 @@
'views/mail_template_po.xml',
'views/price_group.xml',
'views/mrp_production.xml',
+ 'views/apache_solr.xml',
'views/apache_solr_queue.xml',
'views/cost_centre.xml',
'views/account_account_views.xml',
diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py
index 98004f00..eb02cb57 100644
--- a/indoteknik_custom/models/solr/apache_solr.py
+++ b/indoteknik_custom/models/solr/apache_solr.py
@@ -53,6 +53,10 @@ class ApacheSolr(models.Model):
new_dict[cleaned_key] = value
return new_dict
+ def action_commit_collections(self, collections=[]):
+ for collection in collections:
+ self.connect(collection).commit(waitFlush=True, waitSearcher=True)
+
def _update_stock_product_to_solr(self, limit=10000):
current_time = datetime.now()
delta_time = current_time - timedelta(days=3)
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index 452e9b94..7e2a99cc 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -23,10 +23,9 @@ class ProductProduct(models.Model):
def variant_solr_flag_to_solr(self, limit=500):
variant_products = self.search([('solr_flag', '=', 2)], limit=limit)
- if variant_products:
- for product in variant_products:
- product._create_solr_queue('_sync_price_to_solr')
- product.solr_flag = 1
+ for product in variant_products:
+ product.product_tmpl_id._create_solr_queue('_sync_price_to_solr')
+ product.solr_flag = 1
def _sync_variants_to_solr(self):
solr_model = self.env['apache.solr']
diff --git a/indoteknik_custom/models/solr/product_public_category.py b/indoteknik_custom/models/solr/product_public_category.py
index 804624c3..2e2c09f7 100644
--- a/indoteknik_custom/models/solr/product_public_category.py
+++ b/indoteknik_custom/models/solr/product_public_category.py
@@ -67,6 +67,5 @@ class ProductPublicCategory(models.Model):
res = super(ProductPublicCategory, self).unlink()
for rec in self:
self.solr().delete(rec.id)
- self.solr().optimize()
self.solr().commit()
return res \ No newline at end of file
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index ec42746c..3470621e 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -38,10 +38,9 @@ class ProductTemplate(models.Model):
def solr_flag_to_solr(self, limit=500):
template_products = self.search([('solr_flag', '=', 2)], limit=limit)
- if template_products:
- for product in template_products:
- product._create_solr_queue('_sync_price_to_solr')
- product.solr_flag = 1
+ for product in template_products:
+ product._create_solr_queue('_sync_price_to_solr')
+ product.solr_flag = 1
def _sync_active_template_solr(self):
for template in self:
@@ -164,8 +163,6 @@ class ProductTemplate(models.Model):
self.solr().delete(rec.id)
for variant in rec.product_variant_ids:
variant._sync_delete_solr()
- self.solr().optimize()
- self.solr().commit()
def solr_results(self, detail=False):
solr_model = self.env['apache.solr']
diff --git a/indoteknik_custom/views/apache_solr.xml b/indoteknik_custom/views/apache_solr.xml
new file mode 100644
index 00000000..107a713f
--- /dev/null
+++ b/indoteknik_custom/views/apache_solr.xml
@@ -0,0 +1,16 @@
+<odoo>
+ <data noupdate="1">
+ <record id="cron_apache_solr_commit" model="ir.cron">
+ <field name="name">Solr: Commit Collections</field>
+ <field name="interval_number">20</field>
+ <field name="interval_type">minutes</field>
+ <field name="numbercall">-1</field>
+ <field name="doall" eval="False"/>
+ <field name="model_id" ref="model_apache_solr"/>
+ <field name="code">model.action_commit_collections(collections=[])</field>
+ <field name="state">code</field>
+ <field name="priority">50</field>
+ <field name="active">True</field>
+ </record>
+ </data>
+</odoo> \ No newline at end of file