• Dylan Griffith's avatar
    Denormalize project permissions to merge request in Elasticsearch · 31a73793
    Dylan Griffith authored
    As part of our efforts to avoid using joins in Elasticsearch queries
    https://gitlab.com/groups/gitlab-org/-/epics/2054 we need to
    "denormalize" (copy them into child docs) the permission related fields
    needed for searching.
    
    In order to allow us to search for merge requests without joining to the
    project we need to store the `merge_requests_access_level` as well as
    the `visibility_level` of the project on the merge request record.
    
    This MR also introduces an extra field `project_id` for the merge
    request in Elasticsearch which is redundant since we already have
    `target_project_id` and `project_id` is just aliased to this value but
    adding it to Elasticsearch will make the query logic simpler to share
    across all document types. Previously they were all able to consistently
    join to a parent "project" so it helps when changing the code they all
    have a field called `project_id`.
    
    As well as saving these new fields with the merge requests we need to
    also update these fields when they change which we also do in this MR.
    We need to track updates in a few places:
    
    1. When a `ProjectFeature` record is changed (this is where
    `merge_requests_access_level` lives)
    2. When a `Project` is updated (this is where `visibility_level` lives)
    3. When a project is moved to another group. This logic was already
    implemented generically to delegate to `Project` but we update the spec
    for this just to be safe.
    
    The change to index these new fields also introduced an N+1 query which
    required an update to `MergeRequestClassProxy` to preload these new fields
    we're now setting in Elasticsearch.
    
    Changelog: changed
    31a73793
merge_request_class_proxy.rb 1.16 KB