Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidate fetch & fetchpost code #1671

Merged
merged 8 commits into from
Mar 14, 2024
Prev Previous commit
Next Next commit
fetch & fetchpost: consolidate more shared data structures in fet…
…ch.rs
  • Loading branch information
jqnatividad committed Mar 14, 2024
commit 731f8e5040c4ed87d2c337a019cdde73cd247338
20 changes: 10 additions & 10 deletions src/cmd/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ const MIN_WAIT: time::Duration = time::Duration::from_millis(MINIMUM_WAIT_MS);

// for --report option
#[derive(PartialEq)]
enum ReportKind {
pub enum ReportKind {
Detailed,
Short,
None,
Expand Down Expand Up @@ -362,12 +362,12 @@ impl RedisConfig {
}

#[derive(Debug)]
struct DiskCacheConfig {
ttl_secs: u64,
ttl_refresh: bool,
pub struct DiskCacheConfig {
pub ttl_secs: u64,
pub ttl_refresh: bool,
}
impl DiskCacheConfig {
fn new() -> DiskCacheConfig {
pub fn new() -> DiskCacheConfig {
Self {
ttl_secs: std::env::var("QSV_DISKCACHE_TTL_SECS")
.unwrap_or_else(|_| DEFAULT_DISKCACHE_TTL_SECS.to_string())
Expand All @@ -379,7 +379,7 @@ impl DiskCacheConfig {
}

#[derive(Debug, Default, PartialEq)]
enum CacheType {
pub enum CacheType {
#[default]
None,
InMemory,
Expand All @@ -388,10 +388,10 @@ enum CacheType {
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
struct FetchResponse {
response: String,
status_code: u16,
retries: u8,
pub struct FetchResponse {
pub response: String,
pub status_code: u16,
pub retries: u8,
}

static DISKCACHE_DIR: OnceLock<String> = OnceLock::new();
Expand Down
18 changes: 2 additions & 16 deletions src/cmd/fetchpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ use url::Url;

use crate::{
cmd::fetch::{
get_ratelimit_header_value, parse_ratelimit_header_value, process_jql, RedisConfig,
get_ratelimit_header_value, parse_ratelimit_header_value, process_jql, CacheType,
DiskCacheConfig, FetchResponse, RedisConfig, ReportKind,
},
config::{Config, Delimiter},
select::SelectColumns,
Expand Down Expand Up @@ -257,21 +258,6 @@ static DEFAULT_ACCEPT_ENCODING: &str = "br;q=1.0, gzip;q=0.6, deflate;q=0.4, *;q
const MINIMUM_WAIT_MS: u64 = 10;
const MIN_WAIT: time::Duration = time::Duration::from_millis(MINIMUM_WAIT_MS);

// for --report option
#[derive(PartialEq)]
enum ReportKind {
Detailed,
Short,
None,
}

#[derive(Serialize, Deserialize, Clone)]
struct FetchResponse {
response: String,
status_code: u16,
retries: u8,
}

static REDISCONFIG: OnceLock<RedisConfig> = OnceLock::new();

pub fn run(argv: &[&str]) -> CliResult<()> {
Expand Down