Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc1e8002 authored by Nicolas Gelot's avatar Nicolas Gelot
Browse files

Use copy of search data in redis thread

parent 53b1f07a
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
import threading
import threading
import redis
import redis
import pickle
import pickle
import copy


from searx import settings
from searx import settings
from searx.query import SearchQuery
from searx.query import SearchQuery
@@ -60,10 +61,11 @@ class RedisCache(CacheInterface):
        conn.set(key, pickle.dumps(d, protocol=4))
        conn.set(key, pickle.dumps(d, protocol=4))


    def save(self, d):
    def save(self, d):
        data = copy.deepcopy(d)
        threading.Thread(
        threading.Thread(
            target=self._save,
            target=self._save,
            args=(d,),
            args=(data,),
            name='save_search_' + str(d)
            name='save_search_' + str(data)
        ).start()
        ).start()


    def get_twenty_queries(self, x):
    def get_twenty_queries(self, x):
+6 −8
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@ import hmac
import json
import json
import os
import os
import time
import time
import copy


import requests
import requests


@@ -508,21 +507,20 @@ def index():
        else:
        else:
            return index_error(e, output), 500
            return index_error(e, output), 500


    results_copy = copy.deepcopy(search_data.results)
    if is_general_first_page:
    if is_general_first_page:
        images = [r for r in results_copy if r.get('category') == 'images'][:5]
        images = [r for r in search_data.results if r.get('category') == 'images'][:5]
        videos = [r for r in results_copy if r.get('category') == 'videos'][:2]
        videos = [r for r in search_data.results if r.get('category') == 'videos'][:2]
        for res in search_data.results:
        for res in list(search_data.results):
            if res.get('category') != 'general':
            if res.get('category') != 'general':
                results_copy.remove(res)
                search_data.results.remove(res)


    # output
    # output
    config_results(results_copy, search_data.query)
    config_results(search_data.results, search_data.query)
    config_results(images, search_data.query)
    config_results(images, search_data.query)
    config_results(videos, search_data.query)
    config_results(videos, search_data.query)


    response = dict(
    response = dict(
        results=results_copy,
        results=search_data.results,
        q=search_data.query,
        q=search_data.query,
        selected_category=selected_category,
        selected_category=selected_category,
        selected_categories=[selected_category],
        selected_categories=[selected_category],