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 Diff line number Diff line
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):
+6 −8
Original line number Diff line number Diff line
@@ -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],