Class: Banzai::Filter::References::ReferenceCache

Inherits:
Object
  • Object
show all
Includes:
RequestStoreReferenceCache, Gitlab::Utils::StrongMemoize
Defined in:
lib/banzai/filter/references/reference_cache.rb

Instance Method Summary collapse

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

#initialize(filter, context, result) ⇒ ReferenceCache

Returns a new instance of ReferenceCache.



10
11
12
13
14
# File 'lib/banzai/filter/references/reference_cache.rb', line 10

def initialize(filter, context, result)
  @filter = filter
  @context = context
  @result = result || {}
end

Instance Method Details

#cache_loaded?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/banzai/filter/references/reference_cache.rb', line 73

def cache_loaded?
  !!@cache_loaded
end

#current_parent_pathObject



36
37
38
39
40
# File 'lib/banzai/filter/references/reference_cache.rb', line 36

def current_parent_path
  strong_memoize(:current_parent_path) do
    parent&.full_path
  end
end

#current_project_namespace_pathObject



42
43
44
45
46
# File 'lib/banzai/filter/references/reference_cache.rb', line 42

def current_project_namespace_path
  strong_memoize(:current_project_namespace_path) do
    project&.namespace&.full_path
  end
end

#full_group_path(group_ref) ⇒ Object



61
62
63
64
65
# File 'lib/banzai/filter/references/reference_cache.rb', line 61

def full_group_path(group_ref)
  return current_parent_path unless group_ref

  group_ref
end

#full_namespace_path(matches) ⇒ Object



67
68
69
70
71
# File 'lib/banzai/filter/references/reference_cache.rb', line 67

def full_namespace_path(matches)
  return current_parent_path if matches.named_captures['group_or_project_namespace'].blank?

  matches[:group_or_project_namespace]
end

#full_project_path(namespace, project_ref, matches = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/banzai/filter/references/reference_cache.rb', line 48

def full_project_path(namespace, project_ref, matches = nil)
  return current_parent_path unless project_ref

  matched_absolute_path = matches&.named_captures&.fetch('absolute_path')
  namespace ||= current_project_namespace_path unless matched_absolute_path

  full_path = []
  full_path << '/' if matched_absolute_path
  full_path << "#{namespace}/" if namespace
  full_path << project_ref
  full_path.join
end

#load_reference_cache(nodes) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/banzai/filter/references/reference_cache.rb', line 16

def load_reference_cache(nodes)
  load_references_per_parent(nodes)
  load_parent_per_reference
  load_records_per_parent

  @cache_loaded = true
end

#parent_per_referenceObject



28
29
30
# File 'lib/banzai/filter/references/reference_cache.rb', line 28

def parent_per_reference
  @per_reference[parent_type]
end

#records_per_parentObject



32
33
34
# File 'lib/banzai/filter/references/reference_cache.rb', line 32

def records_per_parent
  @_records_per_project[filter.object_class.to_s.underscore]
end

#references_per_parentObject



24
25
26
# File 'lib/banzai/filter/references/reference_cache.rb', line 24

def references_per_parent
  @references_per_parent[parent_type]
end