Run cargo fmt, add root preflight.

This commit is contained in:
Paul Makles
2020-08-04 10:19:33 +02:00
parent 17c9148556
commit d95982fb54
14 changed files with 75 additions and 75 deletions

View File

@@ -1,11 +1,11 @@
use super::get_collection;
use serde::{Deserialize, Serialize};
use rocket::request::FromParam;
use std::sync::{Arc, Mutex};
use mongodb::bson::{Bson, doc, from_bson};
use rocket::http::RawStr;
use lru::LruCache;
use mongodb::bson::{doc, from_bson, Bson};
use rocket::http::RawStr;
use rocket::request::FromParam;
use serde::{Deserialize, Serialize};
use std::sync::{Arc, Mutex};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LastMessage {
@@ -41,7 +41,8 @@ pub struct Channel {
}
lazy_static! {
static ref CACHE: Arc<Mutex<LruCache<String, Channel>>> = Arc::new(Mutex::new(LruCache::new(4_000_000)));
static ref CACHE: Arc<Mutex<LruCache<String, Channel>>> =
Arc::new(Mutex::new(LruCache::new(4_000_000)));
}
pub fn fetch_channel(id: &str) -> Result<Option<Channel>, String> {
@@ -63,7 +64,7 @@ pub fn fetch_channel(id: &str) -> Result<Option<Channel>, String> {
if let Ok(channel) = from_bson(Bson::Document(doc)) as Result<Channel, _> {
let mut cache = CACHE.lock().unwrap();
cache.put(id.to_string(), channel.clone());
Ok(Some(channel))
} else {
Err("Failed to deserialize channel!".to_string())
@@ -84,7 +85,7 @@ pub fn fetch_channels(ids: &Vec<String>) -> Result<Option<Vec<Channel>>, String>
if let Ok(mut cache) = CACHE.lock() {
for gid in ids {
let existing = cache.get(gid);
if let Some(channel) = existing {
channels.push((*channel).clone());
} else {
@@ -97,7 +98,7 @@ pub fn fetch_channels(ids: &Vec<String>) -> Result<Option<Vec<Channel>>, String>
}
if missing.len() == 0 {
return Ok(Some(channels))
return Ok(Some(channels));
}
let col = get_collection("channels");
@@ -109,7 +110,7 @@ pub fn fetch_channels(ids: &Vec<String>) -> Result<Option<Vec<Channel>>, String>
cache.put(channel.id.clone(), channel.clone());
channels.push(channel);
} else {
return Err("Failed to deserialize channel!".to_string())
return Err("Failed to deserialize channel!".to_string());
}
} else {
return Err("Failed to fetch channel.".to_string());
@@ -148,7 +149,7 @@ impl<'r> FromParam<'r> for Channel {
let c = Channel {
id: "potato".to_string(),
channel_type: 0,
active: None,
last_message: None,
description: None,

View File

@@ -1,11 +1,11 @@
use super::get_collection;
use serde::{Deserialize, Serialize};
use rocket::request::FromParam;
use std::sync::{Arc, Mutex};
use mongodb::bson::{Bson, doc, from_bson};
use rocket::http::RawStr;
use lru::LruCache;
use mongodb::bson::{doc, from_bson, Bson};
use rocket::http::RawStr;
use rocket::request::FromParam;
use serde::{Deserialize, Serialize};
use std::sync::{Arc, Mutex};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MemberRef {
@@ -49,7 +49,8 @@ pub struct Guild {
}
lazy_static! {
static ref CACHE: Arc<Mutex<LruCache<String, Guild>>> = Arc::new(Mutex::new(LruCache::new(4_000_000)));
static ref CACHE: Arc<Mutex<LruCache<String, Guild>>> =
Arc::new(Mutex::new(LruCache::new(4_000_000)));
}
pub fn fetch_guild(id: &str) -> Result<Option<Guild>, String> {
@@ -71,7 +72,7 @@ pub fn fetch_guild(id: &str) -> Result<Option<Guild>, String> {
if let Ok(guild) = from_bson(Bson::Document(doc)) as Result<Guild, _> {
let mut cache = CACHE.lock().unwrap();
cache.put(id.to_string(), guild.clone());
Ok(Some(guild))
} else {
Err("Failed to deserialize guild!".to_string())

View File

@@ -1,15 +1,15 @@
use super::get_collection;
use crate::database::channel::Channel;
use crate::notifications;
use crate::notifications::events::message::Create;
use crate::notifications::events::Notification;
use crate::routes::channel::ChannelType;
use crate::database::channel::Channel;
use super::get_collection;
use crate::notifications;
use mongodb::bson::{doc, to_bson, Bson, DateTime};
use serde::{Deserialize, Serialize};
use rocket::request::FromParam;
use mongodb::bson::from_bson;
use mongodb::bson::{doc, to_bson, Bson, DateTime};
use rocket::http::RawStr;
use rocket::request::FromParam;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct PreviousEntry {

View File

@@ -1,5 +1,5 @@
use mongodb::sync::{Client, Collection, Database};
use mongodb::bson::doc;
use mongodb::sync::{Client, Collection, Database};
use std::env;
use once_cell::sync::OnceCell;
@@ -10,7 +10,11 @@ pub fn connect() {
Client::with_uri_str(&env::var("DB_URI").expect("DB_URI not in environment variables!"))
.expect("Failed to init db connection.");
client.database("revolt").collection("migrations").find(doc! { }, None).expect("Failed to get migration data from database.");
client
.database("revolt")
.collection("migrations")
.find(doc! {}, None)
.expect("Failed to get migration data from database.");
DBCONN.set(client).unwrap();
}

View File

@@ -1,6 +1,6 @@
use super::mutual::has_mutual_connection;
use crate::database::channel::Channel;
use crate::database::guild::{Guild, Member, get_member, fetch_guild};
use crate::database::guild::{fetch_guild, get_member, Guild, Member};
use crate::database::user::UserRelationship;
use crate::guards::auth::UserRef;