Skip to content

Commit

Permalink
optimize: speed up fav fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
kingwingfly committed May 16, 2024
1 parent a64c524 commit 891ba42
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

### [0.2.17] - 2024-05-12
### [0.2.17] - 2024-05-17

- improve: show more infos(timestamp) in `fav -V`.
- fix: meaningless version message when building without a git tree.
- optimize: speed up `fav fetch`

## [0.2.16] - 2024-05-10

Expand Down
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fav_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_core"
version = "0.0.7"
version = "0.0.8"
authors.workspace = true
description = "Fav's core crate; A collection of traits."
license.workspace = true
Expand Down
1 change: 1 addition & 0 deletions fav_core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ mod tests {
}
}

#[allow(dead_code)]
struct LoginApi;

impl Api for LoginApi {
Expand Down
16 changes: 9 additions & 7 deletions fav_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_utils"
version = "0.0.3"
version = "0.0.4"
authors.workspace = true
description = "Fav's utils crate; A collection of utilities and data structures for the fav project"
license.workspace = true
Expand All @@ -11,29 +11,31 @@ documentation = "https://docs.rs/fav_utils"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# Core
# core
fav_core.workspace = true
# CLI
indicatif = { version = "0.17", features = ["tokio"] }
# Serde
# serde
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
# ProtoBuf
# protoBuf
protobuf = { version = "3", features = ["with-bytes"] }
protobuf-json-mapping = { version = "3" }
# Net
# net
reqwest = { version = "0.12", features = ["json", "cookies"] }
url = "2.5"
# Runtime
# async
tokio = { version = "1", features = [
"macros",
"rt-multi-thread",
"signal",
"process",
] }
tokio-stream = { version = "0.1" }
futures = "0.3"
# tracing
tracing = { version = "0.1" }
# Tools
# tools
qrcode = { version = "0.14", default-features = false }
tempfile = "3.10.1"
sanitize-filename = "0.5.0"
Expand Down
18 changes: 11 additions & 7 deletions fav_utils/src/bili/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::api::ApiKind;
use super::{Bili, BiliRes, BiliSet, BiliSets};
use crate::{utils::qr::show_qr_code, FavUtilsError, FavUtilsResult};
use fav_core::{prelude::*, status::SetStatusExt as _};
use futures::StreamExt;
use reqwest::Response;
use std::collections::HashMap;
use tokio::time::{sleep, Duration};
Expand Down Expand Up @@ -66,13 +67,16 @@ impl SetOps for Bili {
async fn fetch_set(&self, set: &mut BiliSet) -> FavCoreResult<()> {
let id = set.id.to_string();
info!("Fetching set<{}>", id);
for pn in 1..=set.media_count.saturating_sub(1) / 20 + 1 {
let pn = pn.to_string();
let params = vec![id.clone(), pn, "20".to_string()];
*set |= self
.request_proto::<BiliSet>(ApiKind::FetchSet, params, "/data")
.await?
.with_res_status_on(StatusFlags::FAV);
let page_count = set.media_count.saturating_sub(1) / 20 + 1;
let mut stream = tokio_stream::iter(1..=page_count)
.map(|pn| {
let pn = pn.to_string();
let params = vec![id.clone(), pn, "20".to_string()];
self.request_proto::<BiliSet>(ApiKind::FetchSet, params, "/data")
})
.buffer_unordered(10);
while let Some(res) = stream.next().await {
*set |= res?.with_res_status_on(StatusFlags::FAV);
}
info!("Fetch set<{}> successfully.", id);
Ok(())
Expand Down

0 comments on commit 891ba42

Please sign in to comment.