Skip to content

Reduce 'cached' calls for Banzai

What does this MR do?

As part of &3873 (closed), This MR reduces number of CACHE SQL calls for Banzai::ReferenceFilters and Banzai::ReferenceParser. It should reduce N+1 cache queries for Projects::NotesController#create. But it will also affect BlobController#index, File Preview, IssuePreview, ...

Testing

I tested with adding a note with 1500 lines that contain several references to the same label, user, MR, issue and snippet:

Screenshot_at_Jul_13_18-46-35

Before

{
   "method":"POST",
   "path":"/root/gitlabhq_import/notes",
   "format":"json",
   "controller":"Projects::NotesController",
   "action":"create",
   "status":200,
   "time":"2020-07-10T18:09:36.140Z",
   "params":[
      {
         "key":"note",
         "value":"[FILTERED]"
      },
   ],
   "remote_ip":"127.0.0.1",
   "user_id":1,
   "username":"root",
   "queue_duration_s":0.173198,
   "cpu_s":14.28,
   "db_duration_s":0.41195,
   "view_duration_s":0.06596,
   "duration_s":14.7631,
   "db_count":3153,
   "db_write_count":7,
   "db_cached_count":3082
}

After

{
   "method":"POST",
   "path":"/root/gitlabhq_import/notes",
   "format":"json",
   "controller":"Projects::NotesController",
   "action":"create",
   "status":200,
   "time":"2020-07-10T18:19:22.068Z",
   "params":[
      {
         "key":"note",
         "value":"[FILTERED]"
      }
   ],
   "remote_ip":"127.0.0.1",
   "user_id":1,
   "username":"root",
   "queue_duration_s":0.126337,
   "cpu_s":9.24,
   "db_duration_s":0.27321,
   "view_duration_s":0.27896,
   "duration_s":9.28027,
   "db_count":97,
   "db_write_count":7,
   "db_cached_count":25
}

I tested with comments with a different number of lines to make sure that db_cached_count is always constant.

Conformity

Closes #228626 (closed)

Edited by Nikola Milojevic

Merge request reports