gitlab-org--gitlab-foss/spec/models/concerns
Sean McGivern 991bf24ec8 Use latest_merge_request_diff association
Compared to the merge_request_diff association:

1. It's simpler to query. The query uses a foreign key to the
   merge_request_diffs table, so no ordering is necessary.
2. It's faster for preloading. The merge_request_diff association has to load
   every diff for the MRs in the set, then discard all but the most recent for
   each. This association means that Rails can just query for N diffs from N
   MRs.
3. It's more complicated to update. This is a bidirectional foreign key, so we
   need to update two tables when adding a diff record. This also means we need
   to handle this as a special case when importing a GitLab project.

There is some juggling with this association in the merge request model:

* `MergeRequest#latest_merge_request_diff` is _always_ the latest diff.
* `MergeRequest#merge_request_diff` reuses
  `MergeRequest#latest_merge_request_diff` unless:
    * Arguments are passed. These are typically to force-reload the association.
    * It doesn't exist. That means we might be trying to implicitly create a
      diff. This only seems to happen in specs.
    * The association is already loaded. This is important for the reasons
      explained in the comment, which I'll reiterate here: if we a) load a
      non-latest diff, then b) get its `merge_request`, then c) get that MR's
      `merge_request_diff`, we should get the diff we loaded in c), even though
      that's not the latest diff.

Basically, `MergeRequest#merge_request_diff` is the latest diff in most cases,
but not quite all.
2017-11-23 12:14:56 +00:00
..
access_requestable_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
avatarable_spec.rb Always return full avatar URL for private/internal groups/projects when asset host is set 2017-11-09 15:40:41 +00:00
awardable_spec.rb Add filter by my reaction 2017-08-30 07:48:55 +00:00
cache_markdown_field_spec.rb Create idea of read-only database 2017-10-06 22:37:40 +02:00
case_sensitivity_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
discussion_on_diff_spec.rb Remove superfluous type defs in specs 2017-07-27 14:31:52 +02:00
each_batch_spec.rb Added EachBatch for iterating tables in batches 2017-07-07 16:39:36 +02:00
editable_spec.rb replace `is_edited?` with `edited?` 2017-08-29 11:14:41 +03:00
expirable_spec.rb
faster_cache_keys_spec.rb
feature_gate_spec.rb Rename FLippable to FeatureGate and make `flipper_group` and `user` mutually exclusive 2017-06-27 18:59:51 +02:00
group_descendant_spec.rb Force parents to be preloaded for building a hierarchy 2017-10-05 11:10:57 +02:00
has_status_spec.rb Add a additional scope related to alive CI/CD statuses 2017-10-05 11:30:21 +02:00
has_variable_spec.rb Improve small things 2017-06-28 15:25:36 +09:00
ignorable_column_spec.rb updated the ignore_column concern to support multiple columns 2017-11-06 10:20:20 -05:00
issuable_spec.rb Add total_time_spent to the `changes` hash in issuable Webhook payloads 2017-11-15 15:42:19 +01:00
loaded_in_group_list_spec.rb Pass `archived:` as a keyword argument 2017-10-12 11:36:54 +02:00
manual_inverse_association_spec.rb Use latest_merge_request_diff association 2017-11-23 12:14:56 +00:00
mentionable_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
milestoneish_spec.rb Add feature test to milestone 2017-11-11 16:47:39 +02:00
noteable_spec.rb Remove superfluous type defs in specs 2017-07-27 14:31:52 +02:00
participable_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
presentable_spec.rb
project_features_compatibility_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
reactive_caching_spec.rb Enable the RSpec/HookArgument cop and auto-correct offenses 2017-08-10 19:29:42 -04:00
relative_positioning_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
resolvable_discussion_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
resolvable_note_spec.rb Fix note resolution specs 2017-09-06 10:10:16 +01:00
routable_spec.rb Add system hooks user_rename and group_rename 2017-11-03 11:26:52 +00:00
sha_attribute_spec.rb Fix another typo in SHA attribute spec 2017-07-07 11:06:31 -07:00
spammable_spec.rb Enable RSpec/FilePath cop 2017-04-26 12:50:32 +01:00
strip_attribute_spec.rb Enable RSpec/FilePath cop 2017-04-26 12:50:32 +01:00
subscribable_spec.rb Load participants async 2017-10-31 16:15:03 +00:00
token_authenticatable_spec.rb Remove authentication using user.private_token 2017-11-02 11:39:02 +01:00
uniquify_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