Commit 7f28d757 authored by Dylan Griffith's avatar Dylan Griffith

Ensure wiki cache expires correctly in PostReceive

This should expire just the same as the project cache. This fixes an
issue where wiki cache is causing Elastic indexing to not happen after
creating a new page.
parent a97c8792
......@@ -43,7 +43,8 @@ class PostReceive
return false unless user
# We only need to expire certain caches once per push
expire_caches(post_received)
expire_caches(post_received, post_received.project.repository)
enqueue_repository_cache_update(post_received)
post_received.enum_for(:changes_refs).with_index do |(oldrev, newrev, ref), index|
service_klass =
......@@ -72,18 +73,14 @@ class PostReceive
after_project_changes_hooks(post_received, user, refs.to_a, changes)
end
# Expire the project, branch, and tag cache once per push. Schedule an
# update for the repository size and commit count if necessary.
def expire_caches(post_received)
project = post_received.project
project.repository.expire_status_cache if project.empty_repo?
project.repository.expire_branches_cache if post_received.includes_branches?
project.repository.expire_caches_for_tags if post_received.includes_tags?
enqueue_repository_cache_update(post_received)
# Expire the repository status, branch, and tag cache once per push.
def expire_caches(post_received, repository)
repository.expire_status_cache if repository.empty?
repository.expire_branches_cache if post_received.includes_branches?
repository.expire_caches_for_tags if post_received.includes_tags?
end
# Schedule an update for the repository size and commit count if necessary.
def enqueue_repository_cache_update(post_received)
stats_to_invalidate = [:repository_size]
stats_to_invalidate << :commit_count if post_received.includes_default_branch?
......@@ -110,6 +107,9 @@ class PostReceive
user = identify_user(post_received)
return false unless user
# We only need to expire certain caches once per push
expire_caches(post_received, post_received.project.wiki.repository)
::Git::WikiPushService.new(post_received.project, user, changes: post_received.enum_for(:changes_refs)).execute
end
......
---
title: Fix bug with new wiki not being indexed
merge_request: 18051
author:
type: fixed
......@@ -43,6 +43,7 @@ describe PostReceive do
before do
allow_any_instance_of(Gitlab::GitPostReceive).to receive(:identify).and_return(empty_project.owner)
# Need to mock here so we can expect calls on project
allow(Gitlab::GlRepository).to receive(:parse).and_return([empty_project, Gitlab::GlRepository::PROJECT])
end
......@@ -102,7 +103,7 @@ describe PostReceive do
end
it 'expires the status cache' do
expect(project).to receive(:empty_repo?).and_return(true)
expect(project.repository).to receive(:empty?).and_return(true)
expect(project.repository).to receive(:expire_status_cache)
perform
......@@ -300,6 +301,11 @@ describe PostReceive do
describe '#process_wiki_changes' do
let(:gl_repository) { "wiki-#{project.id}" }
before do
# Need to mock here so we can expect calls on project
allow(Gitlab::GlRepository).to receive(:parse).and_return([project, Gitlab::GlRepository::WIKI])
end
it 'updates project activity' do
# Force Project#set_timestamps_for_create to initialize timestamps
project
......@@ -314,6 +320,28 @@ describe PostReceive do
.and change(project, :last_repository_updated_at)
end
end
context "branches" do
let(:changes) do
<<~EOF
123456 789012 refs/heads/tést1
123456 789012 refs/heads/tést2
EOF
end
it 'expires the branches cache' do
expect(project.wiki.repository).to receive(:expire_branches_cache).once
perform
end
it 'expires the status cache' do
expect(project.wiki.repository).to receive(:empty?).and_return(true)
expect(project.wiki.repository).to receive(:expire_status_cache)
perform
end
end
end
context "webhook" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment