Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ async fn main() -> Result<(), Error> {
reqwest: Arc::new(reqwest::Client::new()),
};

// guilds::tasks::update_guilds(&app_state.discord_bot, &app_state.pg_pool).await;
setup(app_state.discord_bot.clone());

// Only allow requests from the first-party UI origin(s). This API trusts the
// `Authorization` header for auth, so a permissive `*` origin would let any
// website script requests against it using a token it has obtained.
Expand Down Expand Up @@ -123,10 +120,6 @@ async fn main() -> Result<(), Error> {
}
}

fn setup(discord_bot: Arc<twilight_http::Client>) {
meta::setup(discord_bot);
}

/// Parses the `CORS_ALLOWED_ORIGIN` environment variable into a header value
/// suitable for `CorsLayer::allow_origin`.
///
Expand Down
42 changes: 2 additions & 40 deletions api/src/meta/guilds.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
use crate::AppState;
use crate::discord::{
get_current_user_guild, get_current_user_guilds_prime_cache, get_guild, get_guild_channels,
get_guild_prime_cache,
};
use crate::discord::{get_current_user_guild, get_guild, get_guild_channels};
use crate::utils::member_guilds;
use axum::extract::{Path, State};
use axum::routing::get;
use axum::{Extension, Json, Router};
use http::StatusCode;
use lambda_http::tracing::{debug, error, info, warn};
use lambda_http::tracing::warn;
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use std::ops::{Add, Sub};
use std::sync::Arc;
use std::time::Duration;
use tokio::time::{Instant, sleep};
use twilight_http::Client;
use twilight_model::channel::Channel;
use twilight_model::guild::{Permissions, Role};
Expand All @@ -29,13 +23,6 @@ pub fn router() -> Router<AppState> {
.route("/{guild_id}", get(get_meta_guilds_id))
}

pub fn setup(discord_bot: Arc<Client>) {
info!("Spawning meta cache refresh task");
if false {
tokio::spawn(refresh_meta_cache(discord_bot));
}
}

#[derive(Debug, Serialize, Deserialize)]
struct PartialGuildMeta {
id: Id<GuildMarker>,
Expand Down Expand Up @@ -110,28 +97,3 @@ async fn get_meta_guilds_id(
channels
})))
}

async fn refresh_meta_cache(discord_bot: Arc<Client>) {
loop {
debug!("Refreshing meta cache");
let time = Instant::now();
match get_current_user_guilds_prime_cache(&discord_bot).await {
Ok(guilds) => {
debug!("Refreshing meta cache: {}", guilds.len());
for guild in guilds {
let _ = get_guild_prime_cache(guild.id, &discord_bot).await;
}
}
Err(e) => {
error!("refresh_meta_cache error: {:#?}", e);
}
}
debug!(
"{:?} {:?} Waiting {} seconds",
time,
Instant::now(),
(time.sub(Instant::now()).add(Duration::from_secs(50))).as_secs()
);
sleep((time.sub(Instant::now())).add(Duration::from_secs(50))).await;
}
}
8 changes: 0 additions & 8 deletions api/src/meta/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::AppState;
use axum::Router;
use lambda_http::tracing::info;
use std::sync::Arc;
use twilight_http::Client;

mod guilds;
mod users;
Expand All @@ -12,8 +9,3 @@ pub fn router() -> Router<AppState> {
.nest("/guilds", guilds::router())
.nest("/users", users::router())
}

pub fn setup(discord_bot: Arc<Client>) {
info!("Spawning meta cache refresh task");
guilds::setup(discord_bot);
}