Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
β’
a596c07
1
Parent(s):
a5b7d08
π§ chore: add code to cache the previous & next pages (#160)
Browse files- src/server/routes.rs +41 -6
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 ¶ms.page {
|
98 |
Some(page) => *page,
|
99 |
-
None =>
|
100 |
};
|
101 |
|
102 |
-
let
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
);
|
106 |
-
|
107 |
-
let page_content: String = hbs.render("search", &
|
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 ¶ms.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()
|