Commit 99eefcb54d0f467a96629ef63caaf3cceda18eb6
1 parent
ffa46e02
Exists in
master
and in
4 other branches
Invalidate events cache when project was moved
Showing
2 changed files
with
19 additions
and
0 deletions
Show diff stats
app/models/project.rb
| @@ -423,6 +423,7 @@ class Project < ActiveRecord::Base | @@ -423,6 +423,7 @@ class Project < ActiveRecord::Base | ||
| 423 | gitlab_shell.rm_satellites(old_path_with_namespace) | 423 | gitlab_shell.rm_satellites(old_path_with_namespace) |
| 424 | ensure_satellite_exists | 424 | ensure_satellite_exists |
| 425 | send_move_instructions | 425 | send_move_instructions |
| 426 | + reset_events_cache | ||
| 426 | rescue | 427 | rescue |
| 427 | # Returning false does not rollback after_* transaction but gives | 428 | # Returning false does not rollback after_* transaction but gives |
| 428 | # us information about failing some of tasks | 429 | # us information about failing some of tasks |
| @@ -434,4 +435,19 @@ class Project < ActiveRecord::Base | @@ -434,4 +435,19 @@ class Project < ActiveRecord::Base | ||
| 434 | raise Exception.new('repository cannot be renamed') | 435 | raise Exception.new('repository cannot be renamed') |
| 435 | end | 436 | end |
| 436 | end | 437 | end |
| 438 | + | ||
| 439 | + # Reset events cache related to this project | ||
| 440 | + # | ||
| 441 | + # Since we do cache @event we need to reset cache in special cases: | ||
| 442 | + # * when project was moved | ||
| 443 | + # * when project was renamed | ||
| 444 | + # Events cache stored like events/23-20130109142513. | ||
| 445 | + # The cache key includes updated_at timestamp. | ||
| 446 | + # Thus it will automatically generate a new fragment | ||
| 447 | + # when the event is updated because the key changes. | ||
| 448 | + def reset_events_cache | ||
| 449 | + Event.where(project_id: self.id). | ||
| 450 | + order('id DESC').limit(100). | ||
| 451 | + update_all(updated_at: Time.now) | ||
| 452 | + end | ||
| 437 | end | 453 | end |
app/services/project_transfer_service.rb
| @@ -32,6 +32,9 @@ class ProjectTransferService | @@ -32,6 +32,9 @@ class ProjectTransferService | ||
| 32 | # create satellite repo | 32 | # create satellite repo |
| 33 | project.ensure_satellite_exists | 33 | project.ensure_satellite_exists |
| 34 | 34 | ||
| 35 | + # clear project cached events | ||
| 36 | + project.reset_events_cache | ||
| 37 | + | ||
| 35 | true | 38 | true |
| 36 | end | 39 | end |
| 37 | end | 40 | end |