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 Include new URL helpers retroactively into includers of Gitlab::Routing 2017-07-07 10:43:37 -05:00
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 fix bug in emails destroy service 2017-06-23 16:44:34 +02:00
files Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
groups Make Members with Owner and Master roles always able to create subgroups 2017-09-07 13:47:58 -05:00
issuable fix for Follow-up from "Backport of Multiple Assignees feature 2017-05-11 19:11:49 +03:00
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 Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
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 Merge branch 'snippets-finder-visibility' into 'security' 2017-05-10 16:48:18 +02:00
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 Allow wiki pages to be renamed in the UI 2017-08-03 07:38:11 +07:00
access_token_validation_service.rb `AccessTokenValidationService` accepts `String` or `API::Scope` scopes. 2017-06-30 07:32:25 +00:00
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 Enable the Style/TrailingCommaInLiteral cop 2017-05-10 18:25:45 +02:00
base_service.rb
cohorts_service.rb Use last_activity_on in cohorts 2017-04-14 15:20:55 +02:00
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 Memorize the value in methods rather than local 2017-06-21 20:39:05 +08:00
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 Make Delete Merged Branches handle wildcard protected branches correctly 2017-08-02 14:45:54 +02:00
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 Update tests and application 2017-06-13 16:05:38 +02:00
gravatar_service.rb Add username parameter to gravatar URL 2017-06-01 10:07:24 -05:00
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 Update Prometheus gem to version that explicitly calls `munmap` 2017-07-19 08:54:39 +00:00
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 Rename "Slash commands" to "Quick actions" 2017-06-15 09:01:56 -05:00
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 Fix: Wiki is not searchable with Guest permissions 2017-05-22 19:51:09 +03:00
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 Avoid plucking Todo ids and use sub-queries instead 2017-08-03 16:31:05 +02:00
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