mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-26 03:26:19 +00:00
solo usar últimos 60 días de urls
This commit is contained in:
parent
1230f34aca
commit
abf501bd5e
2 changed files with 21 additions and 10 deletions
|
@ -41,7 +41,10 @@ impl Auto {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let links: Vec<String> = {
|
let links: Vec<String> = {
|
||||||
let mut links = self.db.get_urls_by_domain(supermercado.host()).await?;
|
let mut links = self
|
||||||
|
.db
|
||||||
|
.get_recent_urls_by_domain(supermercado.host())
|
||||||
|
.await?;
|
||||||
if let Some(n) = self.args.n_products {
|
if let Some(n) = self.args.n_products {
|
||||||
links.truncate(n);
|
links.truncate(n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,16 +49,21 @@ impl Db {
|
||||||
.map(|r| r.ean))
|
.map(|r| r.ean))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_urls_by_domain(&self, domain: &str) -> anyhow::Result<Vec<String>> {
|
pub async fn get_recent_urls_by_domain(&self, domain: &str) -> anyhow::Result<Vec<String>> {
|
||||||
let query = format!("%{}%", domain);
|
let query = format!("%{}%", domain);
|
||||||
Ok(
|
let last_60_days: i64 = (now() - Duration::from_secs(60 * 60 * 24 * 60))
|
||||||
sqlx::query!("SELECT url FROM producto_urls WHERE url LIKE ?1;", query)
|
.as_millis()
|
||||||
|
.try_into()?;
|
||||||
|
Ok(sqlx::query!(
|
||||||
|
"SELECT url FROM producto_urls WHERE url LIKE ?1 AND last_seen > ?2;",
|
||||||
|
query,
|
||||||
|
last_60_days
|
||||||
|
)
|
||||||
.fetch_all(&self.read_pool)
|
.fetch_all(&self.read_pool)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|r| r.url)
|
.map(|r| r.url)
|
||||||
.collect(),
|
.collect())
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn save_producto_urls(&self, urls: Vec<String>) -> anyhow::Result<()> {
|
pub async fn save_producto_urls(&self, urls: Vec<String>) -> anyhow::Result<()> {
|
||||||
|
@ -122,8 +127,11 @@ async fn connect_to_db(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn now_ms() -> u128 {
|
fn now_ms() -> u128 {
|
||||||
|
now().as_millis()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn now() -> Duration {
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.expect("Time went backwards")
|
.expect("Time went backwards")
|
||||||
.as_millis()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue