added request cooldowns for google

This commit is contained in:
davidovski 2023-08-25 17:39:08 +01:00
parent 0fd041a353
commit f50022f780
5 changed files with 21 additions and 9 deletions

View File

@ -151,7 +151,8 @@
CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
CURLOPT_MAXREDIRS => 5,
CURLOPT_TIMEOUT => 3,
CURLOPT_VERBOSE => false
CURLOPT_VERBOSE => false,
CURLOPT_FOLLOWLOCATION => true
)
);
?>

View File

@ -36,9 +36,7 @@
if (!$opts->do_fallback)
return array();
require "misc/cooldowns.php";
$cooldowns = load_cooldowns();
$cooldowns = $opts->cooldowns;
error_log("loaded" . count($cooldowns));
error_log(print_r($cooldowns,true));

View File

@ -1,7 +1,6 @@
<?php
class GoogleRequest extends EngineRequest {
function get_request_url()
{
public function get_request_url() {
$query_encoded = str_replace("%22", "\"", urlencode($this->query));
$results = array();

View File

@ -5,19 +5,23 @@
$this->page = $opts->page;
$this->opts = $opts;
$engine = $opts->preferred_engines["text"] ?? "google";
$this->engine = $opts->preferred_engines["text"] ?? "google";
$query_parts = explode(" ", $this->query);
$last_word_query = end($query_parts);
if (substr($this->query, 0, 1) == "!" || substr($last_word_query, 0, 1) == "!")
check_ddg_bang($this->query, $opts);
if ($engine == "google") {
if (has_cooldown($this->engine, $this->opts->cooldowns))
return;
if ($this->engine == "google") {
require "engines/text/google.php";
$this->engine_request = new GoogleRequest($opts, $mh);
}
if ($engine == "duckduckgo") {
if ($this->engine == "duckduckgo") {
require "engines/text/duckduckgo.php";
$this->engine_request = new DuckDuckGoRequest($opts, $mh);
}
@ -27,6 +31,10 @@
}
public function get_results() {
if (!$this->engine_request)
return array();
error_log("fetching googl results");
$results = $this->engine_request->get_results();
if ($this->special_request) {
@ -36,6 +44,9 @@
$results = array_merge(array($special_result), $results);
}
if (count($results) <= 1)
set_cooldown($this->engine, ($opts->request_cooldown ?? "1") * 60, $this->opts->cooldowns);
return $results;
}

View File

@ -111,6 +111,9 @@
}
function fetch_search_results($opts, $do_print) {
require "misc/cooldowns.php";
$opts->cooldowns = load_cooldowns();
$start_time = microtime(true);
$mh = curl_multi_init();
$search_category = init_search($opts, $mh);