summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-04-04 10:40:00 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-04-04 10:40:00 +0700
commit9498bce18a3125babebfd2846a08fd5202336741 (patch)
tree2124f6c4591e06ca392b1dbdf82c9bf487da5228
parent2a0a2ba14501a6becdc7655d8924bfdc1123877e (diff)
add time taken on product sync apache.solr
-rw-r--r--indoteknik_custom/models/apache_solr.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py
index bafd94e5..0759d4a3 100644
--- a/indoteknik_custom/models/apache_solr.py
+++ b/indoteknik_custom/models/apache_solr.py
@@ -3,6 +3,7 @@ from odoo.exceptions import UserError
from datetime import datetime
import logging
import pysolr
+import time
_logger = logging.getLogger(__name__)
@@ -12,12 +13,13 @@ class ApacheSolr(models.Model):
_order = 'id desc'
def _sync_product_to_solr(self, limit = 500):
+ start_time = time.time()
_logger.info('run sync to solr...')
solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30)
query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)]
templates = self.env['product.template'].search(query, limit=limit)
- document = []
+ documents = []
counter = 0
for template in templates:
counter += 1
@@ -54,7 +56,7 @@ class ApacheSolr(models.Model):
category_id = category.id
category_name = category.name
- document=[({
+ document = {
'id': template.id,
'display_name_s': template.display_name,
'name_s': template.name,
@@ -81,9 +83,12 @@ class ApacheSolr(models.Model):
'variants_code_t': variants_code,
'search_rank_i': template.search_rank,
'search_rank_weekly_i': template.search_rank_weekly
- })]
- solr.add(document)
+ }
+ documents.append(document)
template.solr_flag = 1
# add counter for monitoring
- _logger.info('%s / 500' % counter)
- _logger.info('Success add to solr product %s' % template.id)
+ _logger.info('[SYNC_PRODUCT_TO_SOLR] %s/%i' % (counter, limit))
+ _logger.info('[SYNC_PRODUCT_TO_SOLR] Success add to solr product %s' % template.id)
+ solr.add(documents)
+ end_time = time.time()
+ print("[SYNC_PRODUCT_TO_SOLR] Finish task add to solr. Time taken: {:.6f} seconds".format(end_time - start_time))