Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add logs for fixing supply #264

Merged
merged 1 commit into from
Oct 19, 2023
Merged
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
16 changes: 16 additions & 0 deletions api/src/dataloaders/collection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use async_graphql::{dataloader::Loader as DataLoader, FieldError, Result};
use hub_core::tracing::info;
use poem::async_trait;
use redis::{AsyncCommands, Client as Redis};
use sea_orm::{prelude::*, FromQueryResult, QueryFilter, QuerySelect};
Expand Down Expand Up @@ -157,40 +158,51 @@
let redis_key = format!("collection:{key}:supply");
match redis_connection.get::<_, Option<i64>>(&redis_key).await {
Ok(value) => {
info!("Got value from Redis for key: {}", key);
results.insert(*key, value);
},
Err(_) => {
info!("Failed to get value from Redis for key: {}", key);
missing_keys.push(*key);
},
}
}

if missing_keys.is_empty() {
info!("No missing keys, returning results");
return Ok(results);
}

let conn = self.db.get();
let mut computed_supplies: Vec<Uuid> = Vec::new();
info!("Missing keys: {:?}", missing_keys);

let collection_with_drops = collections::Entity::find()
.filter(collections::Column::Id.is_in(missing_keys.iter().map(ToOwned::to_owned)))
.inner_join(drops::Entity)
.select_also(drops::Entity)
.all(conn)
.await?;
info!("Collection with drops: {:?}", collection_with_drops);

for (collection, drop) in collection_with_drops {
if let Some(drop) = drop {
if drop.drop_type == DropType::Open {
info!("Open drop for collection: {}", collection.id);
computed_supplies.push(collection.id);
continue;
}
let redis_key = format!("collection:{}:supply", collection.id);

redis_connection.set(&redis_key, collection.supply).await?;
info!(
"supply: {} for collection {}",
collection.supply, collection.id

Check failure on line 200 in api/src/dataloaders/collection.rs

View workflow job for this annotation

GitHub Actions / Cargo Test

`std::option::Option<i64>` doesn't implement `std::fmt::Display`

Check failure on line 200 in api/src/dataloaders/collection.rs

View workflow job for this annotation

GitHub Actions / clippy/check/doc

`std::option::Option<i64>` doesn't implement `std::fmt::Display`
);

results.insert(collection.id, collection.supply);
} else {
info!("No drop for collection: {}", collection.id);
computed_supplies.push(collection.id);
}
}
Expand All @@ -216,6 +228,10 @@
let redis_key = format!("collection:{key}:supply");

redis_connection.set(&redis_key, count).await?;
info!(
"Set Redis key for computed supply: {} count: {}",
key, count

Check failure on line 233 in api/src/dataloaders/collection.rs

View workflow job for this annotation

GitHub Actions / Cargo Test

`std::option::Option<i64>` doesn't implement `std::fmt::Display`

Check failure on line 233 in api/src/dataloaders/collection.rs

View workflow job for this annotation

GitHub Actions / clippy/check/doc

`std::option::Option<i64>` doesn't implement `std::fmt::Display`
);

results.insert(key, count);
}
Expand Down
Loading