generated from holaplex/hub-rust-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from holaplex/espi/count-caching
Redis Cache Total Mints and Supply
- Loading branch information
Showing
16 changed files
with
427 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,37 @@ | ||
use std::collections::HashMap; | ||
|
||
use async_graphql::{dataloader::Loader as DataLoader, FieldError, Result}; | ||
use async_graphql::{dataloader::Loader, FieldError, Result}; | ||
use poem::async_trait; | ||
use sea_orm::{prelude::*, JoinType, QuerySelect}; | ||
use sea_orm::prelude::*; | ||
|
||
use crate::{ | ||
db::Connection, | ||
entities::{collections, drops}, | ||
objects::Drop, | ||
}; | ||
use crate::{db::Connection, entities::drops, objects::Drop}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Loader { | ||
pub struct DropLoader { | ||
pub db: Connection, | ||
} | ||
|
||
impl Loader { | ||
impl DropLoader { | ||
#[must_use] | ||
pub fn new(db: Connection) -> Self { | ||
Self { db } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl DataLoader<Uuid> for Loader { | ||
impl Loader<Uuid> for DropLoader { | ||
type Error = FieldError; | ||
type Value = Drop; | ||
|
||
async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> { | ||
let drops = drops::Entity::find() | ||
.join(JoinType::InnerJoin, drops::Relation::Collections.def()) | ||
.select_also(collections::Entity) | ||
.filter(drops::Column::Id.is_in(keys.iter().map(ToOwned::to_owned))) | ||
.all(self.db.get()) | ||
.await?; | ||
|
||
drops | ||
Ok(drops | ||
.into_iter() | ||
.map(|(drop, collection)| { | ||
Ok(( | ||
drop.id, | ||
Drop::new( | ||
drop.clone(), | ||
collection.ok_or_else(|| { | ||
FieldError::new(format!("no collection for the drop {}", drop.id)) | ||
})?, | ||
), | ||
)) | ||
}) | ||
.collect::<Result<HashMap<Uuid, Self::Value>>>() | ||
.map(|drop| (drop.id, drop.into())) | ||
.collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.