mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 05:58:21 -05:00
Merge pull request #184 from neon-mmd/improve-results-caching
🔧 Cache next and previous pages on search
This commit is contained in:
commit
23f8c482dc
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -1817,9 +1817,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl"
|
name = "openssl"
|
||||||
version = "0.10.55"
|
version = "0.10.56"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d"
|
checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
@ -1849,9 +1849,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl-sys"
|
name = "openssl-sys"
|
||||||
version = "0.9.90"
|
version = "0.9.91"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6"
|
checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
@ -3534,7 +3534,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "websurfx"
|
name = "websurfx"
|
||||||
version = "0.16.4"
|
version = "0.16.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-cors",
|
"actix-cors",
|
||||||
"actix-files",
|
"actix-files",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "websurfx"
|
name = "websurfx"
|
||||||
version = "0.16.4"
|
version = "0.16.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "An open-source alternative to Searx that provides clean, ad-free, and organic results with incredible speed while keeping privacy and security in mind."
|
description = "An open-source alternative to Searx that provides clean, ad-free, and organic results with incredible speed while keeping privacy and security in mind."
|
||||||
repository = "https://github.com/neon-mmd/websurfx"
|
repository = "https://github.com/neon-mmd/websurfx"
|
||||||
|
@ -13,6 +13,7 @@ use crate::{
|
|||||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||||
use handlebars::Handlebars;
|
use handlebars::Handlebars;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use tokio::join;
|
||||||
|
|
||||||
/// A named struct which deserializes all the user provided search parameters and stores them.
|
/// A named struct which deserializes all the user provided search parameters and stores them.
|
||||||
///
|
///
|
||||||
@ -96,15 +97,49 @@ pub async fn search(
|
|||||||
}
|
}
|
||||||
let page = match ¶ms.page {
|
let page = match ¶ms.page {
|
||||||
Some(page) => *page,
|
Some(page) => *page,
|
||||||
None => 0,
|
None => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = format!(
|
let (_, results, _) = join!(
|
||||||
"http://{}:{}/search?q={}&page={}",
|
results(
|
||||||
config.binding_ip, config.port, query, page
|
format!(
|
||||||
|
"http://{}:{}/search?q={}&page={}",
|
||||||
|
config.binding_ip,
|
||||||
|
config.port,
|
||||||
|
query,
|
||||||
|
page - 1
|
||||||
|
),
|
||||||
|
&config,
|
||||||
|
query.to_string(),
|
||||||
|
page - 1,
|
||||||
|
req.clone(),
|
||||||
|
),
|
||||||
|
results(
|
||||||
|
format!(
|
||||||
|
"http://{}:{}/search?q={}&page={}",
|
||||||
|
config.binding_ip, config.port, query, page
|
||||||
|
),
|
||||||
|
&config,
|
||||||
|
query.to_string(),
|
||||||
|
page,
|
||||||
|
req.clone(),
|
||||||
|
),
|
||||||
|
results(
|
||||||
|
format!(
|
||||||
|
"http://{}:{}/search?q={}&page={}",
|
||||||
|
config.binding_ip,
|
||||||
|
config.port,
|
||||||
|
query,
|
||||||
|
page + 1
|
||||||
|
),
|
||||||
|
&config,
|
||||||
|
query.to_string(),
|
||||||
|
page + 1,
|
||||||
|
req.clone(),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
let results_json = results(url, &config, query.to_string(), page, req).await?;
|
|
||||||
let page_content: String = hbs.render("search", &results_json)?;
|
let page_content: String = hbs.render("search", &results?)?;
|
||||||
Ok(HttpResponse::Ok().body(page_content))
|
Ok(HttpResponse::Ok().body(page_content))
|
||||||
}
|
}
|
||||||
None => Ok(HttpResponse::Found()
|
None => Ok(HttpResponse::Found()
|
||||||
|
Loading…
Reference in New Issue
Block a user