Skip to content

Commit

Permalink
Fix testing errors
Browse files Browse the repository at this point in the history
Fix problem caching Grape::Entity
- This ensures Marshall.dump does not have issues
  with the Grape::Entity object we are caching via Rails.cache
  Reference: ruby-grape/grape-entity#299

Fix missing params for OccurenceCache init

Include force flag in #fetch params

Make sure hash has indifferent access
  • Loading branch information
scardoso committed Jan 15, 2020
1 parent 68b2c77 commit 743bdaf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ee/app/serializers/vulnerabilities/occurrence_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ class Vulnerabilities::OccurrenceEntity < Grape::Entity
def current_user
return request.current_user if request.respond_to?(:current_user)
end

def as_json(*args)
serializable_hash(*args).as_json.with_indifferent_access
end
end
2 changes: 1 addition & 1 deletion ee/lib/gitlab/vulnerabilities/occurence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def vulnerability_findings
def cached_vulnerabilities_findings
results = []
project_ids_to_fetch.each do |project_id|
results += Gitlab::Vulnerabilities::OccurenceCache.new(vulnerable, project_id).fetch
results += Gitlab::Vulnerabilities::OccurenceCache.new(vulnerable, project_id, user).fetch
end

results
Expand Down
2 changes: 1 addition & 1 deletion ee/lib/gitlab/vulnerabilities/occurence_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(vulnerable, project_id, user)
@user = user
end

def fetch
def fetch(force: false)
Rails.cache.fetch(cache_key, force: force, expires_in: 1.day) do
findings = ::Security::VulnerabilityFindingsFinder
.new(vulnerable, params: { project_id: [project_id] })
Expand Down

0 comments on commit 743bdaf

Please sign in to comment.