mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 12:54:42 +00:00
Allow the web client to specify activity bucket durations
This commit is contained in:
parent
1363d2c502
commit
69146fb318
1 changed files with 17 additions and 5 deletions
|
@ -299,6 +299,13 @@ async fn get_user_activity_timeline(
|
||||||
Ok(ErasedJson::pretty(summary))
|
Ok(ErasedJson::pretty(summary))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ActiveUserCountParams {
|
||||||
|
#[serde(flatten)]
|
||||||
|
period: TimePeriodParams,
|
||||||
|
durations_in_minutes: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct ActiveUserSet {
|
struct ActiveUserSet {
|
||||||
active_time_in_minutes: u64,
|
active_time_in_minutes: u64,
|
||||||
|
@ -306,18 +313,23 @@ struct ActiveUserSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_active_user_counts(
|
async fn get_active_user_counts(
|
||||||
Query(params): Query<TimePeriodParams>,
|
Query(params): Query<ActiveUserCountParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
) -> Result<ErasedJson> {
|
) -> Result<ErasedJson> {
|
||||||
let durations_in_minutes = [10, 60, 4 * 60, 8 * 60];
|
let durations_in_minutes = params.durations_in_minutes.split(',');
|
||||||
|
let mut user_sets = Vec::new();
|
||||||
let mut user_sets = Vec::with_capacity(durations_in_minutes.len());
|
|
||||||
for duration in durations_in_minutes {
|
for duration in durations_in_minutes {
|
||||||
|
let duration = duration
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| anyhow!("invalid duration: {duration}"))?;
|
||||||
user_sets.push(ActiveUserSet {
|
user_sets.push(ActiveUserSet {
|
||||||
active_time_in_minutes: duration,
|
active_time_in_minutes: duration,
|
||||||
user_count: app
|
user_count: app
|
||||||
.db
|
.db
|
||||||
.get_active_user_count(params.start..params.end, Duration::from_secs(duration * 60))
|
.get_active_user_count(
|
||||||
|
params.period.start..params.period.end,
|
||||||
|
Duration::from_secs(duration * 60),
|
||||||
|
)
|
||||||
.await?,
|
.await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue