forked from jmug/stoatchat
Update to mongo 1.1.0-beta, start reset + migrations
This commit is contained in:
@@ -3,7 +3,7 @@ use super::get_collection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use rocket::request::FromParam;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use bson::{doc, from_bson};
|
||||
use mongodb::bson::{Bson, doc, from_bson};
|
||||
use rocket::http::RawStr;
|
||||
use lru::LruCache;
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn fetch_channel(id: &str) -> Result<Option<Channel>, String> {
|
||||
let col = get_collection("channels");
|
||||
if let Ok(result) = col.find_one(doc! { "_id": id }, None) {
|
||||
if let Some(doc) = result {
|
||||
if let Ok(channel) = from_bson(bson::Bson::Document(doc)) as Result<Channel, _> {
|
||||
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());
|
||||
|
||||
@@ -105,7 +105,7 @@ pub fn fetch_channels(ids: &Vec<String>) -> Result<Option<Vec<Channel>>, String>
|
||||
for item in result {
|
||||
let mut cache = CACHE.lock().unwrap();
|
||||
if let Ok(doc) = item {
|
||||
if let Ok(channel) = from_bson(bson::Bson::Document(doc)) as Result<Channel, _> {
|
||||
if let Ok(channel) = from_bson(Bson::Document(doc)) as Result<Channel, _> {
|
||||
cache.put(channel.id.clone(), channel.clone());
|
||||
channels.push(channel);
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::get_collection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use rocket::request::FromParam;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use bson::{doc, from_bson};
|
||||
use mongodb::bson::{Bson, doc, from_bson};
|
||||
use rocket::http::RawStr;
|
||||
use lru::LruCache;
|
||||
|
||||
@@ -68,7 +68,7 @@ pub fn fetch_guild(id: &str) -> Result<Option<Guild>, String> {
|
||||
let col = get_collection("guilds");
|
||||
if let Ok(result) = col.find_one(doc! { "_id": id }, None) {
|
||||
if let Some(doc) = result {
|
||||
if let Ok(guild) = from_bson(bson::Bson::Document(doc)) as Result<Guild, _> {
|
||||
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());
|
||||
|
||||
@@ -109,7 +109,7 @@ pub fn get_member(guild_id: &String, member: &String) -> Option<Member> {
|
||||
None,
|
||||
) {
|
||||
if let Some(doc) = result {
|
||||
Some(from_bson(bson::Bson::Document(doc)).expect("Failed to unwrap member."))
|
||||
Some(from_bson(Bson::Document(doc)).expect("Failed to unwrap member."))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -166,7 +166,7 @@ pub fn get_invite<U: Into<Option<String>>>(
|
||||
Some((
|
||||
doc.get_str("_id").unwrap().to_string(),
|
||||
doc.get_str("name").unwrap().to_string(),
|
||||
from_bson(bson::Bson::Document(invite.clone())).unwrap(),
|
||||
from_bson(Bson::Document(invite.clone())).unwrap(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -5,16 +5,16 @@ use crate::database::channel::Channel;
|
||||
use super::get_collection;
|
||||
use crate::notifications;
|
||||
|
||||
use bson::{doc, to_bson, UtcDateTime};
|
||||
use mongodb::bson::{doc, to_bson, Bson, DateTime};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use rocket::request::FromParam;
|
||||
use bson::from_bson;
|
||||
use mongodb::bson::from_bson;
|
||||
use rocket::http::RawStr;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct PreviousEntry {
|
||||
pub content: String,
|
||||
pub time: UtcDateTime,
|
||||
pub time: DateTime,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@@ -26,7 +26,7 @@ pub struct Message {
|
||||
pub author: String,
|
||||
|
||||
pub content: String,
|
||||
pub edited: Option<UtcDateTime>,
|
||||
pub edited: Option<DateTime>,
|
||||
|
||||
pub previous_content: Vec<PreviousEntry>,
|
||||
}
|
||||
@@ -101,7 +101,7 @@ impl<'r> FromParam<'r> for Message {
|
||||
.unwrap();
|
||||
|
||||
if let Some(message) = result {
|
||||
Ok(from_bson(bson::Bson::Document(message)).expect("Failed to unwrap message."))
|
||||
Ok(from_bson(Bson::Document(message)).expect("Failed to unwrap message."))
|
||||
} else {
|
||||
Err(param)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use mongodb::{Client, Collection, Database};
|
||||
use mongodb::sync::{Client, Collection, Database};
|
||||
use mongodb::bson::doc;
|
||||
use std::env;
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
@@ -9,6 +10,8 @@ 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.");
|
||||
|
||||
DBCONN.set(client).unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{get_collection, MemberPermissions};
|
||||
|
||||
use bson::doc;
|
||||
use mongodb::bson::doc;
|
||||
use mongodb::options::FindOptions;
|
||||
|
||||
pub fn find_mutual_guilds(user_id: &str, target_id: &str) -> Vec<String> {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use bson::UtcDateTime;
|
||||
use mongodb::bson::DateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct UserEmailVerification {
|
||||
pub verified: bool,
|
||||
pub target: Option<String>,
|
||||
pub expiry: Option<UtcDateTime>,
|
||||
pub rate_limit: Option<UtcDateTime>,
|
||||
pub expiry: Option<DateTime>,
|
||||
pub rate_limit: Option<DateTime>,
|
||||
pub code: Option<String>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user