MCPcopy Create free account
hub / github.com/emwalker/digraph / main

Function main

backend/src/bin/cron.rs:6–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5#[tokio::main]
6async fn main() -> Result<()> {
7 let config = Config::load()?;
8 env_logger::init();
9 let pool = db::db_connection(&config).await?;
10
11 sqlx::query(
12 r#"
13 with
14
15 topic_stats as (
16 select count(*) count from topics
17 ),
18
19 link_stats as (
20 select count(*) count from links
21 ),
22
23 user_stats as (
24 select count(*) count from users
25 ),
26
27 active_user_stats as (
28 select count(*) count
29 from (
30 select distinct user_id
31 from user_links where created_at > now() - interval '7 days'
32 group by user_id
33 having count(link_id) > 5
34 ) a
35 )
36
37 insert into daily_snapshot (topic_count, link_count, user_count, active_user_count)
38 select sum(t.count), sum(l.count), sum(u.count), sum(au.count)
39 from topic_stats t
40 cross join link_stats l
41 cross join user_stats u
42 cross join active_user_stats au
43 "#,
44 )
45 .execute(&pool)
46 .await?;
47
48 log::info!("daily snapshot taken");
49 Ok(())
50}

Callers

nothing calls this directly

Calls 2

initFunction · 0.85
db_connectionFunction · 0.85

Tested by

no test coverage detected