gitlab-org--gitlab-foss/app/services
Yorick Peterse 83355336dd
Rework how recent push events are retrieved
Whenever you push to a branch GitLab will show a button to create a
merge request (should one not exist already). The underlying code to
display this data was quite inefficient. For example, it involved
multiple slow queries just to figure out what the most recent push event
was.

This commit changes the way this data is retrieved so it's much faster.
This is achieved by caching the ID of the last push event on every push,
which is then retrieved when loading certain pages. Database queries are
only executed if necessary and the cached data is removed automatically
once a merge request has been created, or 2 hours after being stored.

A trade-off of this approach is that we _only_ track the last event.
Previously if you were to push to branch A and B then create a merge
request for branch B we'd still show the widget for branch A. As of this
commit this is no longer the case, instead we will only show the widget
for the branch you pushed to most recently. Once a merge request exists
the widget is no longer displayed. Alternative solutions are either too
complex and/or too slow, hence the decision was made to settle for this
trade-off.

Performance Impact
------------------

In the best case scenario (= a user didn't push anything for more than 2
hours) we perform a single Redis GET per page. Should there be cached
data we will run a single (and lightweight) SQL query to get the
event data from the database. If a merge request already exists we will
run an additional DEL to remove the cache key.

The difference in response timings can vary a bit per project. On
GitLab.com the 99th percentile of time spent in User#recent_push hovers
between 100 milliseconds and 1 second, while the mean hovers around 50
milliseconds. With the changes in this MR the expected time spent in
User#recent_push is expected to be reduced down to just a few
milliseconds.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/35990
2017-09-08 00:46:16 +02:00
..
application_settings
auth current_application_settings belongs on Gitlab::CurrentSettings 2017-08-31 13:38:33 +01:00
boards Small fixes 2017-08-31 16:34:57 -03:00
chat_names
ci refactor Ci::CreatePipelineService#allowed_to_create? 2017-09-07 13:16:15 +03:00
commits Move GitOperationService to Gitlab::Git 2017-09-01 14:37:56 +02:00
concerns Refactor based on code review 2017-09-06 12:07:21 -07:00
discussions Resolve outdated diff discussions on push 2017-09-06 10:08:03 +01:00
emails
files
groups Make Members with Owner and Master roles always able to create subgroups 2017-09-07 13:47:58 -05:00
issuable
issues Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into ee_issue_928_backport 2017-09-06 14:35:58 +10:00
labels Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
mattermost
members Whitelist or fix additional Gitlab/PublicSend cop violations 2017-08-14 12:14:11 -04:00
merge_requests Cleans merge_jid when possible on MergeService 2017-08-28 16:41:05 -03:00
milestones replace is_project_milestone? with project_milestone? 2017-08-29 11:14:41 +03:00
notes
projects Refactor based on code review 2017-09-06 12:07:21 -07:00
protected_branches
protected_tags
quick_actions Removes default scope from sortable 2017-09-07 13:01:59 +01:00
search
tags Move GitHooksService to Gitlab::Git 2017-08-23 10:45:20 +02:00
test_hooks Fix a wrong X-Gitlab-Event header when testing webhooks 2017-09-07 17:40:32 +02:00
users Rework how recent push events are retrieved 2017-09-08 00:46:16 +02:00
wiki_pages
access_token_validation_service.rb
after_branch_delete_service.rb
akismet_service.rb current_application_settings belongs on Gitlab::CurrentSettings 2017-08-31 13:38:33 +01:00
audit_event_service.rb
base_service.rb
cohorts_service.rb
compare_service.rb Prepare GitOperationService for move to Gitlab::Git 2017-08-31 15:35:59 +02:00
create_branch_service.rb Move GitHooksService to Gitlab::Git 2017-08-23 10:45:20 +02:00
create_deployment_service.rb
create_release_service.rb
create_snippet_service.rb
delete_branch_service.rb Move GitHooksService to Gitlab::Git 2017-08-23 10:45:20 +02:00
delete_merged_branches_service.rb
event_create_service.rb Rework how recent push events are retrieved 2017-09-08 00:46:16 +02:00
git_push_service.rb replace is_default_branch? with default_branch? 2017-08-29 11:14:42 +03:00
git_tag_push_service.rb
gravatar_service.rb
ham_service.rb
import_export_clean_up_service.rb
issuable_base_service.rb Merge branch 'remove-finder-caching' into 'master' 2017-09-01 18:39:12 +00:00
metrics_service.rb
note_summary.rb
notification_recipient_service.rb actually use the :participating notification type 2017-08-21 15:34:24 -07:00
notification_service.rb Whitelist or fix additional Gitlab/PublicSend cop violations 2017-08-14 12:14:11 -04:00
pages_service.rb
preview_markdown_service.rb
push_event_payload_service.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
repair_ldap_blocked_user_service.rb
repository_archive_clean_up_service.rb
search_service.rb
spam_check_service.rb
spam_service.rb replace is_spam? with spam? 2017-08-29 11:14:42 +03:00
submit_usage_ping_service.rb Store & use ConvDev percentages returned by Version app 2017-08-07 20:52:08 +02:00
system_hooks_service.rb Whitelist or fix additional Gitlab/PublicSend cop violations 2017-08-14 12:14:11 -04:00
system_note_service.rb replace is_group_milestone? with group_milestone? 2017-08-29 11:14:41 +03:00
todo_service.rb
update_release_service.rb
update_snippet_service.rb
upload_service.rb current_application_settings belongs on Gitlab::CurrentSettings 2017-08-31 13:38:33 +01:00
user_agent_detail_service.rb
user_project_access_changed_service.rb Move sidekiq-based project authorization refresh out of Projects::CreateService 2017-08-25 16:19:32 +01:00
validate_new_branch_service.rb Move GitHooksService to Gitlab::Git 2017-08-23 10:45:20 +02:00
web_hook_service.rb Fix a wrong X-Gitlab-Event header when testing webhooks 2017-09-07 17:40:32 +02:00