gitlab-org--gitlab-foss/spec/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
..
auth Rename user_can_admin? because it's more accurate 2017-08-07 17:29:34 +08:00
boards Backport specs 2017-08-31 15:18:35 -03:00
chat_names Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
ci Merge branch 'zj-auto-devops-table' into 'master' 2017-09-07 17:28:30 +00:00
discussions Resolve outdated diff discussions on push 2017-09-06 10:08:03 +01:00
emails Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
files Move GitHooksService to Gitlab::Git 2017-08-23 10:45:20 +02:00
groups Make Members with Owner and Master roles always able to create subgroups 2017-09-07 13:47:58 -05:00
issuable Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02: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 Enable the RSpec/HookArgument cop and auto-correct offenses 2017-08-10 19:29:42 -04:00
members Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
merge_requests Cleans merge_jid when possible on MergeService 2017-08-28 16:41:05 -03:00
milestones Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
notes Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
projects Adds exclusive lease to Git garbage collect worker. 2017-09-07 18:52:04 +01:00
protected_branches Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
protected_tags Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
quick_actions /move project functionality. Squash commit. 2017-08-31 21:30:36 +01:00
search Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04: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 Merge branch 'wiki_title' into 'master' 2017-08-07 16:37:44 +00:00
access_token_validation_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
after_branch_delete_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
cohorts_service_spec.rb Enable the Style/TrailingCommaInLiteral cop 2017-05-10 18:25:45 +02:00
compare_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
create_branch_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
create_deployment_service_spec.rb Fix more tests 2017-08-11 17:54:34 +08:00
create_release_service_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
create_snippet_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
delete_branch_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
delete_merged_branches_service_spec.rb Make Delete Merged Branches handle wildcard protected branches correctly 2017-08-02 14:45:54 +02:00
event_create_service_spec.rb Rework how recent push events are retrieved 2017-09-08 00:46:16 +02:00
git_push_service_spec.rb replace `is_default_branch?` with `default_branch?` 2017-08-29 11:14:42 +03:00
git_tag_push_service_spec.rb Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
gravatar_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
import_export_clean_up_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
note_summary_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
notification_service_spec.rb Removes default scope from sortable 2017-09-07 13:01:59 +01:00
pages_service_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
preview_markdown_service_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
push_event_payload_service_spec.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
repair_ldap_blocked_user_service_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
repository_archive_clean_up_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
search_service_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
spam_service_spec.rb replace `is_spam?` with `spam?` 2017-08-29 11:14:42 +03:00
submit_usage_ping_service_spec.rb Store & use ConvDev percentages returned by Version app 2017-08-07 20:52:08 +02:00
system_hooks_service_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
system_note_service_spec.rb Optimize system note service specs 2017-08-31 12:37:01 +02:00
todo_service_spec.rb Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
update_release_service_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
update_snippet_service_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
upload_service_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
user_project_access_changed_service_spec.rb Move sidekiq-based project authorization refresh out of Projects::CreateService 2017-08-25 16:19:32 +01:00
web_hook_service_spec.rb Fix a wrong `X-Gitlab-Event` header when testing webhooks 2017-09-07 17:40:32 +02:00