Commit 081aa0b8 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'osw-refresh-forks-count-cache-correctly' into 'master'

Ensure forks count cache refresh for source project

See merge request gitlab-org/gitlab!21771
parents e68c3744 ee3e0405
......@@ -3,11 +3,16 @@
module Projects
class ForkService < BaseService
def execute(fork_to_project = nil)
if fork_to_project
link_existing_project(fork_to_project)
else
fork_new_project
end
forked_project =
if fork_to_project
link_existing_project(fork_to_project)
else
fork_new_project
end
refresh_forks_count if forked_project&.saved?
forked_project
end
private
......@@ -92,8 +97,7 @@ module Projects
def link_fork_network(fork_to_project)
return if fork_to_project.errors.any?
fork_to_project.fork_network_member.save &&
refresh_forks_count
fork_to_project.fork_network_member.save
end
def refresh_forks_count
......
---
title: Ensure forks count cache refresh for source project
merge_request: 21771
author:
type: fixed
......@@ -6,6 +6,16 @@ describe Projects::ForkService do
include ProjectForksHelper
include Gitlab::ShellAdapter
shared_examples 'forks count cache refresh' do
it 'flushes the forks count cache of the source project', :clean_gitlab_redis_cache do
expect(from_project.forks_count).to be_zero
fork_project(from_project, to_user)
expect(from_project.forks_count).to eq(1)
end
end
context 'when forking a new project' do
describe 'fork by user' do
before do
......@@ -40,6 +50,11 @@ describe Projects::ForkService do
end
end
it_behaves_like 'forks count cache refresh' do
let(:from_project) { @from_project }
let(:to_user) { @to_user }
end
describe "successfully creates project in the user namespace" do
let(:to_project) { fork_project(@from_project, @to_user, namespace: @to_user.namespace) }
......@@ -62,12 +77,9 @@ describe Projects::ForkService do
expect(@from_project.avatar.file).to be_exists
end
it 'flushes the forks count cache of the source project' do
expect(@from_project.forks_count).to be_zero
fork_project(@from_project, @to_user)
expect(@from_project.forks_count).to eq(1)
it_behaves_like 'forks count cache refresh' do
let(:from_project) { @from_project }
let(:to_user) { @to_user }
end
it 'creates a fork network with the new project and the root project set' do
......@@ -102,6 +114,11 @@ describe Projects::ForkService do
it 'sets the forked_from_project on the membership' do
expect(to_project.fork_network_member.forked_from_project).to eq(from_forked_project)
end
it_behaves_like 'forks count cache refresh' do
let(:from_project) { from_forked_project }
let(:to_user) { @to_user }
end
end
end
......
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