Commit bc1e8002 authored by Nicolas Gelot's avatar Nicolas Gelot

Use copy of search data in redis thread

parent 53b1f07a
import threading
import redis
import pickle
import copy
from searx import settings
from searx.query import SearchQuery
......@@ -60,10 +61,11 @@ class RedisCache(CacheInterface):
conn.set(key, pickle.dumps(d, protocol=4))
def save(self, d):
data = copy.deepcopy(d)
threading.Thread(
target=self._save,
args=(d,),
name='save_search_' + str(d)
args=(data,),
name='save_search_' + str(data)
).start()
def get_twenty_queries(self, x):
......
......@@ -22,7 +22,6 @@ import hmac
import json
import os
import time
import copy
import requests
......@@ -508,21 +507,20 @@ def index():
else:
return index_error(e, output), 500
results_copy = copy.deepcopy(search_data.results)
if is_general_first_page:
images = [r for r in results_copy if r.get('category') == 'images'][:5]
videos = [r for r in results_copy if r.get('category') == 'videos'][:2]
for res in search_data.results:
images = [r for r in search_data.results if r.get('category') == 'images'][:5]
videos = [r for r in search_data.results if r.get('category') == 'videos'][:2]
for res in list(search_data.results):
if res.get('category') != 'general':
results_copy.remove(res)
search_data.results.remove(res)
# output
config_results(results_copy, search_data.query)
config_results(search_data.results, search_data.query)
config_results(images, search_data.query)
config_results(videos, search_data.query)
response = dict(
results=results_copy,
results=search_data.results,
q=search_data.query,
selected_category=selected_category,
selected_categories=[selected_category],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment