gitlab-org--gitlab-foss/app/services
Yorick Peterse 0395c47193
Migrate events into a new format
This commit migrates events data in such a way that push events are
stored much more efficiently. This is done by creating a shadow table
called "events_for_migration", and a table called "push_event_payloads"
which is used for storing push data of push events. The background
migration in this commit will copy events from the "events" table into
the "events_for_migration" table, push events in will also have a row
created in "push_event_payloads".

This approach allows us to reclaim space in the next release by simply
swapping the "events" and "events_for_migration" tables, then dropping
the old events (now "events_for_migration") table.

The new table structure is also optimised for storage space, and does
not include the unused "title" column nor the "data" column (since this
data is moved to "push_event_payloads").

== Newly Created Events

Newly created events are inserted into both "events" and
"events_for_migration", both using the exact same primary key value. The
table "push_event_payloads" in turn has a foreign key to the _shadow_
table. This removes the need for recreating and validating the foreign
key after swapping the tables. Since the shadow table also has a foreign
key to "projects.id" we also don't have to worry about orphaned rows.

This approach however does require some additional storage as we're
duplicating a portion of the events data for at least 1 release. The
exact amount is hard to estimate, but for GitLab.com this is expected to
be between 10 and 20 GB at most. The background migration in this commit
deliberately does _not_ update the "events" table as doing so would put
a lot of pressure on PostgreSQL's auto vacuuming system.

== Supporting Both Old And New Events

Application code has also been adjusted to support push events using
both the old and new data formats. This is done by creating a PushEvent
class which extends the regular Event class. Using Rails' Single Table
Inheritance system we can ensure the right class is used for the right
data, which in this case is based on the value of `events.action`. To
support displaying old and new data at the same time the PushEvent class
re-defines a few methods of the Event class, falling back to their
original implementations for push events in the old format.

Once all existing events have been migrated the various push event
related methods can be removed from the Event model, and the calls to
`super` can be removed from the methods in the PushEvent model.

The UI and event atom feed have also been slightly changed to better
handle this new setup, fortunately only a few changes were necessary to
make this work.

== API Changes

The API only displays push data of events in the new format. Supporting
both formats in the API is a bit more difficult compared to the UI.
Since the old push data was not really well documented (apart from one
example that used an incorrect "action" nmae) I decided that supporting
both was not worth the effort, especially since events will be migrated
in a few days _and_ new events are created in the correct format.
2017-08-10 17:45:44 +02:00
..
application_settings
auth Rename user_can_admin? because it's more accurate 2017-08-07 17:29:34 +08:00
boards Clear issuable counter caches on update 2017-07-19 10:21:20 +01:00
chat_names Include new URL helpers retroactively into includers of Gitlab::Routing 2017-07-07 10:43:37 -05:00
ci Add two more metrics for CI/CD 2017-07-31 11:51:28 +02:00
commits Refactor changing files in web UI 2017-04-20 00:37:44 +00:00
concerns/issues Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
discussions Update diff discussion position per discussion instead of per note 2017-05-31 14:34:56 -05: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 Remove Mattermost team with GitLab group 2017-07-28 09:09:55 +02:00
issuable fix for Follow-up from "Backport of Multiple Assignees feature 2017-05-11 19:11:49 +03:00
issues Simplify checking if objects exist code in new issaubles workers 2017-08-08 12:43:55 +02:00
labels Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
mattermost
members Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
merge_requests Simplify checking if objects exist code in new issaubles workers 2017-08-08 12:43:55 +02:00
milestones Repair Regression caused by - !11573 2017-07-11 14:23:51 +08:00
notes Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
projects Add checks for branch existence before changing HEAD 2017-08-08 12:10:55 +11:00
protected_branches Protected Tags backend review changes 2017-04-06 10:56:21 +01:00
protected_tags Protected Tags backend review changes 2017-04-06 10:56:21 +01:00
quick_actions Add `/assign me` alias support for assigning issuables to oneself 2017-08-07 14:40:33 +02:00
search Merge branch 'snippets-finder-visibility' into 'security' 2017-05-10 16:48:18 +02:00
tags Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
test_hooks Wrong data type when testing webhooks 2017-07-20 15:12:06 +00:00
users Use Ghost user when edited_by, merged_by deleted 2017-07-19 11:35:17 +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 Enable the Style/TrailingCommaInLiteral cop 2017-05-10 18:25:45 +02:00
audit_event_service.rb Enable the Style/TrailingCommaInLiteral cop 2017-05-10 18:25:45 +02:00
base_service.rb Log errors in UpdatePagesService 2017-03-31 16:15:10 +02:00
cohorts_service.rb Use last_activity_on in cohorts 2017-04-14 15:20:55 +02:00
compare_service.rb Fix Diff::Position#diff_file for positions on straight diffs 2017-06-06 14:48:05 -05:00
create_branch_service.rb
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 Add confirm delete protected branch modal 2017-05-08 07:41:58 +00: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 Migrate events into a new format 2017-08-10 17:45:44 +02:00
git_hooks_service.rb Set the GL_REPOSITORY env variable on Gitlab::Git::Hook 2017-06-29 15:22:40 -04:00
git_operation_service.rb Rename many path_with_namespace -> full_path 2017-08-01 07:26:58 +02:00
git_push_service.rb Merge branch 'dm-large-push-performance' into 'master' 2017-07-28 17:03:17 +00: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 '32844-issuables-performance' into 'master' 2017-08-07 21:21:29 +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 rubocop style fix 2017-08-03 09:07:18 -07:00
notification_service.rb another rubocop style fix 2017-08-03 11:52:53 -07: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
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 Rename many path_with_namespace -> full_path 2017-08-01 07:26:58 +02:00
system_note_service.rb Create system notes for group milestone changes 2017-08-07 11:55:00 +01: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 Support uploaders for personal snippets comments 2017-05-02 15:22:24 +02:00
user_agent_detail_service.rb
user_project_access_changed_service.rb
validate_new_branch_service.rb Refactor changing files in web UI 2017-04-20 00:37:44 +00:00
web_hook_service.rb Fix encoding error for WebHook logging 2017-08-01 20:19:59 +03:00