I use GraphQL in my Net core application. I discovered that for the same query, the first query took quite a long time (about 1400ms). But when I query again, the time is only 20ms, the next time too. Why?
This is my code
[UseDbContext(typeof(StudentManagerContext))]
public async Task<List<CourseType>> GetAllCourseUsingDataLoader([ScopedService] StudentManagerContext context)
{
var stopwatch = Stopwatch.StartNew(); //
var courses = await courseRepo.LoadAllCourse();
var r = courses
.Select(course => new CourseType
{
Id = course.Id,
CourseName = course.CourseName,
Description = course.Description,
Teacher = course.Teacher,
StudentCourses = course.StudentCourses,
}).ToList();
stopwatch.Stop();
logger.LogCritical($"In querry request took {stopwatch.ElapsedMilliseconds} ms"); //
return r;
}
I tried other queries, all got the same situation.