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 #257 from holaplex/revert-256-espi/count-caching
Revert "Total mints and supply cache counters"
- Loading branch information
Showing
16 changed files
with
193 additions
and
422 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,37 +1,53 @@ | ||
use std::collections::HashMap; | ||
|
||
use async_graphql::{dataloader::Loader, FieldError, Result}; | ||
use async_graphql::{dataloader::Loader as DataLoader, FieldError, Result}; | ||
use poem::async_trait; | ||
use sea_orm::prelude::*; | ||
use sea_orm::{prelude::*, JoinType, QuerySelect}; | ||
|
||
use crate::{db::Connection, entities::drops, objects::Drop}; | ||
use crate::{ | ||
db::Connection, | ||
entities::{collections, drops}, | ||
objects::Drop, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct DropLoader { | ||
pub struct Loader { | ||
pub db: Connection, | ||
} | ||
|
||
impl DropLoader { | ||
impl Loader { | ||
#[must_use] | ||
pub fn new(db: Connection) -> Self { | ||
Self { db } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Loader<Uuid> for DropLoader { | ||
impl DataLoader<Uuid> for Loader { | ||
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?; | ||
|
||
Ok(drops | ||
drops | ||
.into_iter() | ||
.map(|drop| (drop.id, drop.into())) | ||
.collect()) | ||
.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>>>() | ||
} | ||
} |
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.