import { db , mongooseModels } from "./db" ; import { query , lookup } from "@bluelibs/nova" ; import * as Benchmark from "benchmark" ; import { ITestSuite } from "../common" ; import { GROUPS } from "../constants" ; export const suites = [ { name : "Full Database Dump - Users" , async run ( ) { const results = await mongooseModels . User . find ( { } , "email name" ) . populate ( { path : "groups" , select : "name" , } ) . populate ( { path : "posts" , select : "title description" , populate : [ { path : "category" , select : "name" , } , { path : "tags" , select : "name" , } , { path : "comments" , select : "text" , populate : { path : "user" , select : "email name" , } , } , ] , } ) . exec ( ) ; return results ; } , } , { name : "Users with groups" , async run ( ) { const results = await mongooseModels . User . find ( { } , "email name" ) . populate ( { path : "groups" , select : "name" , } ) . exec ( ) ; return results ; } , } , { name : "Posts with tags, comments and users email" , async run ( ) { const results = await mongooseModels . Post . find ( { } , "title description" ) . populate ( { path : "tags" , select : "name" , } ) . populate ( { path : "comments" , select : "text" , populate : { path : "user" , select : "email name" , } , } ) . exec ( ) ; return results ; } , } , { name : "Full Database Dump - Comments" , async run ( ) { const results = await mongooseModels . Comment . find ( { } , "text" ) . populate ( { path : "user" , select : "email" , populate : { path : "groups" , select : "name" , } , } ) . populate ( { path : "post" , select : "title description" , populate : [ { path : "category" , select : "name" , } , { path : "tags" , select : "name" , } , { path : "user" , select : "email name" , } , ] , } ) . exec ( ) ; return results ; } , } , { name : "Get all posts that belong to users in a specific group" , skip : true , async run ( ) { const group = await db . Groups . findOne ( { name : GROUPS [ 0 ] } , { projection : { _id : 1 , } , } ) ; const users = await db . Users . find ( { groupsIds : group . _id , } , { projection : { _id : 1 , } , } ) . toArray ( ) ; const userIds = users . map ( ( user ) => user . _id ) ; const result = await query ( db . Posts , { $ : { filters : { userId : { $in : userIds , } , } , } , _id : 1 , title : 1 , category : { _id : 1 , name : 1 , } , tags : { _id : 1 , name : 1 , } , user : { _id : 1 , email : 1 , groups : { _id : 1 , name : 1 , } , } , } ) . toArray ( ) ; return result ; } , } , { name : "Get all posts sorted by category name" , skip : true , async run ( ) { const result = await query ( db . Posts , { $ : { pipeline : [ lookup ( db . Posts , "category" ) , { $sort : { "category.name" : 1 , } , } , ] , } , _id : 1 , title : 1 , category : { name : 1 , _id : 1 , } , tags : { name : 1 , _id : 1 , } , user : { email : 1 , _id : 1 , groups : { _id : 1 , name : 1 , } , } , } ) . toArray ( ) ; return result ; } , } , ] ;