Class: Projects::Forks::Details

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/models/projects/forks/details.rb

Overview

Class for calculating the divergence of a fork with the source project

Constant Summary collapse

LATEST_COMMITS_COUNT =
10
LEASE_TIMEOUT =
15.minutes.to_i
EXPIRATION_TIME =
8.hours

Instance Method Summary collapse

Constructor Details

#initialize(project, ref) ⇒ Details

Returns a new instance of Details.



13
14
15
16
17
18
# File 'app/models/projects/forks/details.rb', line 13

def initialize(project, ref)
  @project = project
  @fork_repo = project.repository
  @source_repo = project.fork_source.repository
  @ref = ref
end

Instance Method Details

#countsObject



20
21
22
23
24
# File 'app/models/projects/forks/details.rb', line 20

def counts
  ahead, behind = divergence_counts

  { ahead: ahead, behind: behind }
end

#exclusive_leaseObject



26
27
28
29
30
31
# File 'app/models/projects/forks/details.rb', line 26

def exclusive_lease
  key = ['project_details', project.id, ref].join(':')
  uuid = Gitlab::ExclusiveLease.get_uuid(key)

  Gitlab::ExclusiveLease.new(key, uuid: uuid, timeout: LEASE_TIMEOUT)
end

#has_conflicts?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/projects/forks/details.rb', line 38

def has_conflicts?
  !(attrs && attrs[:has_conflicts]).nil?
end

#syncing?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/projects/forks/details.rb', line 34

def syncing?
  exclusive_lease.exists?
end

#update!(params) ⇒ Object



42
43
44
45
46
# File 'app/models/projects/forks/details.rb', line 42

def update!(params)
  Rails.cache.write(cache_key, params, expires_in: EXPIRATION_TIME)

  @attrs = nil
end