gitlab-org--gitlab-foss/app/models
Timothy Andrew ba25e2f1ac Improve performance of the cycle analytics page.
1. These changes bring down page load time for 100 issues from more than
   a minute to about 1.5 seconds.

2. This entire commit is composed of these types of performance
   enhancements:

     - Cache relevant data in `IssueMetrics` wherever possible.
     - Cache relevant data in `MergeRequestMetrics` wherever possible.
     - Preload metrics

3. Given these improvements, we now only need to make 4 SQL calls:

    - Load all issues
    - Load all merge requests
    - Load all metrics for the issues
    - Load all metrics for the merge requests

4. A list of all the data points that are now being pre-calculated:

    a. The first time an issue is mentioned in a commit

      - In `GitPushService`, find all issues mentioned by the given commit
        using `ReferenceExtractor`. Set the `first_mentioned_in_commit_at`
        flag for each of them.

      - There seems to be a (pre-existing) bug here - files (and
        therefore commits) created using the Web CI don't have
        cross-references created, and issues are not closed even when
        the commit title is "Fixes #xx".

    b. The first time a merge request is deployed to production

      When a `Deployment` is created, find all merge requests that
      were merged in before the deployment, and set the
      `first_deployed_to_production_at` flag for each of them.

    c. The start / end time for a merge request pipeline

      Hook into the `Pipeline` state machine. When the `status` moves to
      `running`, find the merge requests whose tip commit matches the
      pipeline, and record the `latest_build_started_at` time for each
      of them. When the `status` moves to `success`, record the
      `latest_build_finished_at` time.

    d. The merge requests that close an issue

      - This was a big cause of the performance problems we were having
        with Cycle Analytics. We need to use `ReferenceExtractor` to make
        this calculation, which is slow when we have to run it on a large
        number of merge requests.

      - When a merge request is created, updated, or refreshed, find the
        issues it closes, and create an instance of
        `MergeRequestsClosingIssues`, which acts as a join model between
        merge requests and issues.

      - If a `MergeRequestsClosingIssues` instance links a merge request
        and an issue, that issue closes that merge request.

5. The `Queries` module was changed into a class, so we can cache the
   results of `issues` and `merge_requests_closing_issues` across
   various cycle analytics stages.

6. The code added in this commit is untested. Tests will be added in the
   next commit.
2016-09-15 14:53:02 +05:30
..
ci Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
concerns wip: perf 2016-09-14 19:40:31 +05:30
cycle_analytics Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
hooks Scope hooks thal will run for confidential issues 2016-08-31 18:34:45 -03:00
issue Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
members Merge branch 'master' into expiration-date-on-memberships 2016-08-18 15:54:07 +01:00
merge_request Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
network Enable Style/SpaceAfterComma Rubocop cop 2016-06-29 15:23:44 +02:00
project_services Add option to confidential issues events to trigger services 2016-08-31 18:34:45 -03:00
protected_branch Backport changes from gitlab-org/gitlab-ee!581 to CE. 2016-08-16 11:05:14 +05:30
.gitkeep
ability.rb factor out a RuleSet so that `delegate!` retains @cannot 2016-08-30 11:39:22 -07:00
abuse_report.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
appearance.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
application_setting.rb Remove gitorious 2016-08-25 10:10:10 +01:00
audit_event.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
award_emoji.rb Add emoji.rb in lib/gitlab instead of using the gitlab_emoji gem. 2016-06-29 14:53:09 -06:00
blob.rb Limit the size of SVGs when viewing them as blobs 2016-08-15 13:42:52 +02:00
board.rb The lists: Backlog, and Done cannot be destroyed 2016-08-17 12:58:57 -03:00
broadcast_message.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
commit.rb Use JavaScript tooltips for mentions (!5301) 2016-09-01 01:21:34 +02:00
commit_range.rb Use JavaScript tooltips for mentions (!5301) 2016-09-01 01:21:34 +02:00
commit_status.rb Merge branch 'statuseable-hasstatus' into 'master' 2016-08-25 18:49:03 +00:00
compare.rb Make Compare#diffs diff_options a regular argument 2016-08-03 09:32:01 -07:00
cycle_analytics.rb Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
deploy_key.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
deploy_keys_project.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
deployment.rb Method names changed to #includes_commit? 2016-08-12 10:43:04 +02:00
diff_note.rb Move #to_discussion to NoteOnDiff 2016-08-30 16:30:42 +01:00
discussion.rb Fix bug where notes weren’t shown in discussion when the code had changed after creation 2016-08-19 12:38:40 -05:00
email.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
environment.rb Method names changed to #includes_commit? 2016-08-12 10:43:04 +02:00
event.rb remove Ability.abilities 2016-08-30 11:35:06 -07:00
external_issue.rb
forked_project_link.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
generic_commit_status.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
global_label.rb
global_milestone.rb
group.rb Add expiration date to group memberships 2016-08-18 21:09:17 +01:00
identity.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
issue.rb Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
key.rb Add simple identifier to public SSH keys 2016-08-02 06:56:23 +01:00
label.rb Destroy related lists when a label is removed 2016-08-17 12:58:58 -03:00
label_link.rb squashed - fixed label and milestone association problems, updated specs and refactored reader class a bit 2016-08-01 09:57:40 +02:00
legacy_diff_note.rb Move #to_discussion to NoteOnDiff 2016-08-30 16:30:42 +01:00
lfs_object.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
lfs_objects_project.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
list.rb Add a movable scope and a movable? method to List model 2016-08-17 12:58:59 -03:00
member.rb Allow project group links to be expired 2016-08-18 22:45:41 +01:00
merge_request.rb Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
merge_request_diff.rb Change the way merge request diff compare works 2016-08-25 11:58:17 +03:00
merge_requests_closing_issues.rb Improve performance of the cycle analytics page. 2016-09-15 14:53:02 +05:30
milestone.rb use has_many relationship with events 2016-07-01 15:34:10 +02:00
namespace.rb Fix bug where destroying a namespace would not always destroy projects 2016-08-11 15:36:35 -07:00
note.rb prevent authored awardable thumbs votes 2016-08-28 18:15:55 +01:00
notification_setting.rb Exclude projects pending delete from notifications 2016-07-07 20:49:17 +01:00
oauth_access_token.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
personal_access_token.rb Address @DouweM's feedback on !3749. 2016-04-28 22:28:36 +05:30
personal_snippet.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
project.rb Project tools visibility level 2016-09-01 11:47:59 -03:00
project_feature.rb Project tools visibility level 2016-09-01 11:47:59 -03:00
project_group_link.rb Allow project group links to be expired 2016-08-18 22:45:41 +01:00
project_import_data.rb add missing attribute to attr_encrypted so it is fully backwards-compatible 2016-06-28 09:55:19 +02:00
project_snippet.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
project_team.rb Add expiration date to group memberships 2016-08-18 21:09:17 +01:00
project_wiki.rb Add method missing from EE 2016-08-12 21:56:40 -04:00
protected_branch.rb Backport changes from gitlab-org/gitlab-ee!581 to CE. 2016-08-16 11:05:14 +05:30
release.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
repository.rb Make error message appropriate for end users 2016-09-02 17:54:09 +02:00
security_event.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
sent_notification.rb Allow SentNotification#position to be set as string or hash 2016-07-11 12:21:05 -05:00
service.rb Scope hooks thal will run for confidential issues 2016-08-31 18:34:45 -03:00
snippet.rb Merge branch 'feature/custom-highlighting' into 'master' 2016-06-28 08:42:42 +00:00
spam_log.rb Allow `SpamLog` to be submitted as ham 2016-08-15 13:18:15 -05:00
subscription.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
todo.rb Todos sorting dropdown 2016-08-19 16:14:20 -03:00
tree.rb
u2f_registration.rb Allow naming U2F devices. 2016-08-18 22:12:02 +05:30
user.rb Project tools visibility level 2016-09-01 11:47:59 -03:00
user_agent_detail.rb Further refactor and syntax fixes. 2016-08-15 17:20:57 -05:00
users_star_project.rb Revert "Fix merge conflicts - squashed commit" 2016-06-03 11:10:17 +02:00
wiki_page.rb `WikiPage` should have a slug even when not persisted. 2016-07-25 09:22:47 +05:30