Skip to content

Commit

Permalink
Fix staging dashboard caching
Browse files Browse the repository at this point in the history
after_save hooks in derived classe aren't taken into account,
so implement a hook in the base class that can overloaded

The users were happy about the performance, but noticed 3
days into the change that projects didn't move - so let's
correctly invalidate caches
  • Loading branch information
coolo committed Jan 24, 2019
1 parent f5e3acd commit 2c57ca6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/api/app/models/event/base.rb
Expand Up @@ -77,6 +77,7 @@ def inherited(subclass)
super

subclass.after_create_commit(:send_to_bus)
subclass.after_create_commit(:clear_caches)
subclass.add_classname(name) unless name == 'Event::Base'
subclass.payload_keys(*payload_keys)
subclass.create_jobs(*create_jobs)
Expand Down Expand Up @@ -273,6 +274,10 @@ def send_to_bus
RabbitmqBus.send_to_bus('metrics', to_metric) if metric_fields.present?
end

def clear_caches
# no default implementation
end

private

def message_bus_routing_key
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/models/event/build.rb
Expand Up @@ -4,7 +4,6 @@ class Build < Base
self.abstract_class = true
payload_keys :project, :package, :sender, :repository, :arch, :release, :readytime, :srcmd5,
:rev, :reason, :bcnt, :verifymd5, :hostarch, :starttime, :endtime, :workerid, :versrel, :previouslyfailed
after_save :clear_cache

def my_message_id
# we put the verifymd5 sum in the message id, so new checkins get new thread, but it doesn't have to be very correct
Expand All @@ -23,7 +22,7 @@ def custom_headers

private

def clear_cache
def clear_caches
Rails.cache.delete("failed_results-#{payload[:project]}")
end
end
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/models/event/repo_build_finished.rb
Expand Up @@ -3,11 +3,10 @@ class RepoBuildFinished < Base
self.message_bus_routing_key = 'repo.build_finished'
self.description = 'Repository finished building'
payload_keys :project, :repo, :arch, :buildid
after_save :clear_cache

private

def clear_cache
def clear_caches
# TODO: We should touch the repository instead of deleting the key
# to invalidate the cache. However, repository currently does not have
# an updated_at column so we can not use Rails' cache_key method.
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/models/event/repo_build_started.rb
Expand Up @@ -3,11 +3,10 @@ class RepoBuildStarted < Base
self.message_bus_routing_key = 'repo.build_started'
self.description = 'Repository (re)started building'
payload_keys :project, :repo, :arch, :buildid
after_save :clear_cache

private

def clear_cache
def clear_caches
# TODO: We should touch the repository instead of deleting the key
# to invalidate the cache. However, repository currently does not have
# an updated_at column so we can not use Rails' cache_key method.
Expand Down
3 changes: 1 addition & 2 deletions src/api/app/models/event/repo_published.rb
Expand Up @@ -3,11 +3,10 @@ class RepoPublished < Base
self.message_bus_routing_key = 'repo.published'
self.description = 'Repository was published'
payload_keys :project, :repo, :buildid
after_save :clear_cache

private

def clear_cache
def clear_caches
# TODO: We should touch the repository instead of deleting the key
# to invalidate the cache. However, repository currently does not have
# an updated_at column so we can not use Rails' cache_key method.
Expand Down

0 comments on commit 2c57ca6

Please sign in to comment.