In graphQL, the first query always takes longer than the next query for the same query

In graphQL, the first query always takes longer than the next query for the same query


0

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.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *