AbstractReferenceFilter should cache on projects ref cache the current project path with namespace
While working on improving the 'post-receive-job' in the context of #18663 (moved) I've found that processing commits with messages with references to the current project in the form of Issue #1
(without specifying the path and namespace to the project) are not cached in the RequestStore so all the commits while execute queries to return that project.
project = Project.find_with_namespace("")
author = project.creator
commit = project.commit
extractor = commit.all_references("#1") # where that issue exist into that project
extractor.send(:html_documents) # To limit the execution just render the message of the commit
With the previous script, you'll see we always execute a request to find the project asking for the path_with_namespace
SELECT "projects"."id" AS t0_r0, "projects"."name" AS t0_r1, "projects"."path" AS t0_r2, "projects"."description" AS t0_r3, "projects"."created_at" AS t0_r4, "projects"."updated_at" AS t0_r5, "projects"."creator_id" AS t0_r6, "projects"."namespace_id" AS t0_r7, "projects"."last_activity_at" AS t0_r8, "projects"."import_url" AS t0_r9, "projects"."visibility_level" AS t0_r10, "projects"."archived" AS t0_r11, "projects"."avatar" AS t0_r12, "projects"."import_status" AS t0_r13, "projects"."repository_size" AS t0_r14, "projects"."star_count" AS t0_r15, "projects"."import_type" AS t0_r16, "projects"."import_source" AS t0_r17, "projects"."commit_count" AS t0_r18, "projects"."import_error" AS t0_r19, "projects"."ci_id" AS t0_r20, "projects"."shared_runners_enabled" AS t0_r21, "projects"."runners_token" AS t0_r22, "projects"."build_coverage_regex" AS t0_r23, "projects"."build_allow_git_fetch" AS t0_r24, "projects"."build_timeout" AS t0_r25, "projects"."pending_delete" AS t0_r26, "projects"."public_builds" AS t0_r27, "projects"."last_repository_check_failed" AS t0_r28, "projects"."last_repository_check_at" AS t0_r29, "projects"."container_registry_enabled" AS t0_r30, "projects"."only_allow_merge_if_build_succeeds" AS t0_r31, "projects"."has_external_issue_tracker" AS t0_r32, "projects"."repository_storage" AS t0_r33, "projects"."request_access_enabled" AS t0_r34, "projects"."has_external_wiki" AS t0_r35, "projects"."lfs_enabled" AS t0_r36, "namespaces"."id" AS t1_r0, "namespaces"."name" AS t1_r1, "namespaces"."path" AS t1_r2, "namespaces"."owner_id" AS t1_r3, "namespaces"."created_at" AS t1_r4, "namespaces"."updated_at" AS t1_r5, "namespaces"."type" AS t1_r6, "namespaces"."description" AS t1_r7, "namespaces"."avatar" AS t1_r8, "namespaces"."share_with_group_lock" AS t1_r9, "namespaces"."visibility_level" AS t1_r10, "namespaces"."request_access_enabled" AS t1_r11, "namespaces"."deleted_at" AS t1_r12, "namespaces"."lfs_enabled" AS t1_r13, "services"."id" AS t2_r0, "services"."type" AS t2_r1, "services"."title" AS t2_r2, "services"."project_id" AS t2_r3, "services"."created_at" AS t2_r4, "services"."updated_at" AS t2_r5, "services"."active" AS t2_r6, "services"."properties" AS t2_r7, "services"."template" AS t2_r8, "services"."push_events" AS t2_r9, "services"."issues_events" AS t2_r10, "services"."merge_requests_events" AS t2_r11, "services"."tag_push_events" AS t2_r12, "services"."note_events" AS t2_r13, "services"."build_events" AS t2_r14, "services"."category" AS t2_r15, "services"."default" AS t2_r16, "services"."wiki_page_events" AS t2_r17, "services"."pipeline_events" AS t2_r18, "services"."confidential_issues_events" AS t2_r19 FROM "projects" INNER JOIN "namespaces" ON "namespaces"."id" = "projects"."namespace_id" AND "namespaces"."deleted_at" IS NULL LEFT OUTER JOIN "services" ON "services"."project_id" = "projects"."id" AND "services"."type" IN ('GitlabIssueTrackerService') WHERE "projects"."pending_delete" = $1 AND ((
(namespaces.path = 'gitlab-org'
AND projects.path = 'gitlab-ce')
OR (
LOWER(namespaces.path) = LOWER('gitlab-org')
AND LOWER(projects.path) = LOWER('gitlab-ce')
)
)) ORDER BY "projects"."id" DESC [["pending_delete", "f"]]
As when executing a git push of commits that are referencing the same issue or different issues to the current project and considering that this are new commits so the html document is not cache. I think we shoudl try to avoid those queries and store the data on the RequestStore as we're doing when referencing using the path_with_namespace gitlab-org/gitlab-ce#1
this commit message won't execute the project request for subsequent commit messages on the same request that point to that project