alamin655 commited on
Commit
23f8c48
2 Parent(s): 9fd8275 f8bd25b

Merge pull request #184 from neon-mmd/improve-results-caching

Browse files
Files changed (3) hide show
  1. Cargo.lock +5 -5
  2. Cargo.toml +1 -1
  3. src/server/routes.rs +41 -6
Cargo.lock CHANGED
@@ -1817,9 +1817,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575"
1817
 
1818
  [[package]]
1819
  name = "openssl"
1820
- version = "0.10.55"
1821
  source = "registry+https://github.com/rust-lang/crates.io-index"
1822
- checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d"
1823
  dependencies = [
1824
  "bitflags 1.3.2",
1825
  "cfg-if 1.0.0",
@@ -1849,9 +1849,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
1849
 
1850
  [[package]]
1851
  name = "openssl-sys"
1852
- version = "0.9.90"
1853
  source = "registry+https://github.com/rust-lang/crates.io-index"
1854
- checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6"
1855
  dependencies = [
1856
  "cc",
1857
  "libc",
@@ -3534,7 +3534,7 @@ dependencies = [
3534
 
3535
  [[package]]
3536
  name = "websurfx"
3537
- version = "0.16.4"
3538
  dependencies = [
3539
  "actix-cors",
3540
  "actix-files",
 
1817
 
1818
  [[package]]
1819
  name = "openssl"
1820
+ version = "0.10.56"
1821
  source = "registry+https://github.com/rust-lang/crates.io-index"
1822
+ checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e"
1823
  dependencies = [
1824
  "bitflags 1.3.2",
1825
  "cfg-if 1.0.0",
 
1849
 
1850
  [[package]]
1851
  name = "openssl-sys"
1852
+ version = "0.9.91"
1853
  source = "registry+https://github.com/rust-lang/crates.io-index"
1854
+ checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac"
1855
  dependencies = [
1856
  "cc",
1857
  "libc",
 
3534
 
3535
  [[package]]
3536
  name = "websurfx"
3537
+ version = "0.16.5"
3538
  dependencies = [
3539
  "actix-cors",
3540
  "actix-files",
Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
  [package]
2
  name = "websurfx"
3
- version = "0.16.4"
4
  edition = "2021"
5
  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."
6
  repository = "https://github.com/neon-mmd/websurfx"
 
1
  [package]
2
  name = "websurfx"
3
+ version = "0.16.5"
4
  edition = "2021"
5
  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."
6
  repository = "https://github.com/neon-mmd/websurfx"
src/server/routes.rs CHANGED
@@ -13,6 +13,7 @@ use crate::{
13
  use actix_web::{get, web, HttpRequest, HttpResponse};
14
  use handlebars::Handlebars;
15
  use serde::Deserialize;
 
16
 
17
  /// A named struct which deserializes all the user provided search parameters and stores them.
18
  ///
@@ -96,15 +97,49 @@ pub async fn search(
96
  }
97
  let page = match &params.page {
98
  Some(page) => *page,
99
- None => 0,
100
  };
101
 
102
- let url = format!(
103
- "http://{}:{}/search?q={}&page={}",
104
- config.binding_ip, config.port, query, page
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  );
106
- let results_json = results(url, &config, query.to_string(), page, req).await?;
107
- let page_content: String = hbs.render("search", &results_json)?;
108
  Ok(HttpResponse::Ok().body(page_content))
109
  }
110
  None => Ok(HttpResponse::Found()
 
13
  use actix_web::{get, web, HttpRequest, HttpResponse};
14
  use handlebars::Handlebars;
15
  use serde::Deserialize;
16
+ use tokio::join;
17
 
18
  /// A named struct which deserializes all the user provided search parameters and stores them.
19
  ///
 
97
  }
98
  let page = match &params.page {
99
  Some(page) => *page,
100
+ None => 1,
101
  };
102
 
103
+ let (_, results, _) = join!(
104
+ results(
105
+ format!(
106
+ "http://{}:{}/search?q={}&page={}",
107
+ config.binding_ip,
108
+ config.port,
109
+ query,
110
+ page - 1
111
+ ),
112
+ &config,
113
+ query.to_string(),
114
+ page - 1,
115
+ req.clone(),
116
+ ),
117
+ results(
118
+ format!(
119
+ "http://{}:{}/search?q={}&page={}",
120
+ config.binding_ip, config.port, query, page
121
+ ),
122
+ &config,
123
+ query.to_string(),
124
+ page,
125
+ req.clone(),
126
+ ),
127
+ results(
128
+ format!(
129
+ "http://{}:{}/search?q={}&page={}",
130
+ config.binding_ip,
131
+ config.port,
132
+ query,
133
+ page + 1
134
+ ),
135
+ &config,
136
+ query.to_string(),
137
+ page + 1,
138
+ req.clone(),
139
+ )
140
  );
141
+
142
+ let page_content: String = hbs.render("search", &results?)?;
143
  Ok(HttpResponse::Ok().body(page_content))
144
  }
145
  None => Ok(HttpResponse::Found()