Skip to content

Commit

Permalink
perf(services/exporter): remove n+1 query
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Dec 11, 2024
1 parent b086443 commit 29cd04d
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions crates/services/exporter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use chrono::{DateTime, Utc};
use common_models::ExportJob;
use common_utils::{IsFeatureEnabled, TEMP_DIR};
use database_models::{
exercise,
prelude::{
Exercise, Metadata, MetadataGroup, Person, Seen, UserToEntity, Workout, WorkoutTemplate,
},
Expand Down Expand Up @@ -372,19 +373,12 @@ impl ExporterService {
user_id: &String,
writer: &mut JsonStreamWriter<StdFile>,
) -> Result<()> {
let exercises = UserToEntity::find()
.filter(user_to_entity::Column::UserId.eq(user_id))
.filter(user_to_entity::Column::ExerciseId.is_not_null())
let exercises = Exercise::find()
.filter(exercise::Column::CreatedByUserId.eq(user_id))
.all(&self.0.db)
.await
.unwrap();
for rm in exercises.iter() {
let e = rm
.find_related(Exercise)
.one(&self.0.db)
.await
.unwrap()
.unwrap();
for e in exercises {
let reviews = item_reviews(user_id, &e.id, EntityLot::Exercise, false, &self.0)
.await?
.into_iter()
Expand All @@ -397,7 +391,7 @@ impl ExporterService {
.map(|c| c.name)
.collect();
let exp = ImportOrExportExerciseItem {
name: e.id,
name: e.name,
collections,
reviews,
};
Expand Down

0 comments on commit 29cd04d

Please sign in to comment.