Commit Graph

601 Commits

Author SHA1 Message Date
Sean McGivern 4ebbfe5d3e Remove serialised diff and commit columns
The st_commits and st_diffs columns on merge_request_diffs historically held the
YAML-serialised data for a merge request diff, in a variety of formats.

Since 9.5, these have been migrated in the background to two new tables:
merge_request_diff_commits and merge_request_diff_files. That has the advantage
that we can actually query the data (for instance, to find out how many commits
we've stored), and that it can't be in a variety of formats, but must match the
new schema.

This is the final step of that journey, where we drop those columns and remove
all references to them. This is a breaking change to the importer, because we
can no longer import diffs created in the old format, and we cannot guarantee
the export will be in the new format unless it was generated after this commit.
2017-11-28 16:13:40 +00:00
George Andrinopoulos 7fb1bb01bd Create issue and merge request destroy services 2017-11-25 22:09:18 +02:00
Sean McGivern c4d844f08b Merge branch 'issue_40374' into 'master'
Fix WIP system note not being created

Closes #40374

See merge request gitlab-org/gitlab-ce!15528
2017-11-24 09:38:45 +00:00
Felipe Artur 5c2c471a83 Fix WIP system note not being created 2017-11-23 17:25:14 -02:00
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
George Andrinopoulos 3963f91ee3 Move update_project_counter_caches? out of issue and merge request 2017-11-11 21:06:28 +02:00
Sean McGivern ec73ecb0a8 Fix another timeout when searching for pipelines
When we consider 'all' pipelines for MRs, we now mean:

1. The last 10,000 commits (unordered).
2. From the last 100 MR versions (newest first).

This seems to fix the MRs that time out on GitLab.com.
2017-11-10 14:27:26 +00:00
Rémy Coutable bf13746fd8 Merge branch 'dm-notes-for-commit-id' into 'master'
Use Commit#notes and Note.for_commit_id when possible to make sure we use all indexes available to us

Closes #34509

See merge request gitlab-org/gitlab-ce!15253
2017-11-08 16:04:15 +00:00
Douwe Maan fec48c6e17 Use Commit#notes and Note.for_commit_id when possible to make sure we use all the indexes available to us 2017-11-08 12:22:11 +01:00
Jarka Kadlecova ad6e650262 Refactor issuables index actions 2017-11-07 14:34:12 +01:00
micael.bergeron bb0543ef47 ignore the column before the migration
reword the changelog
remove dead code in the specs
2017-11-06 09:03:11 -05:00
micael.bergeron cd88fa8f80 removed the #ensure_ref_fetched from all controllers
also, I refactored the MergeRequest#fetch_ref method to express
the side-effect that this method has.

  MergeRequest#fetch_ref -> MergeRequest#fetch_ref!
  Repository#fetch_source_branch -> Repository#fetch_source_branch!
2017-11-03 08:13:11 -04:00
Jarka Kadlecova 064c8949bd CE port of code changed for epics 2017-11-02 07:14:35 +01:00
Yorick Peterse c14697a50b Merge branch '39054-activerecord-statementinvalid-pg-querycanceled-error-canceling-statement-due-to-statement-timeout' into 'master'
Resolve "ActiveRecord::StatementInvalid: PG::QueryCanceled: ERROR:  canceling statement due to statement timeout"

Closes #39054

See merge request gitlab-org/gitlab-ce!15063
2017-10-30 11:57:09 +00:00
Oswaldo Ferreira c4124fce48 Move locked check to a guard-clause 2017-10-30 11:21:23 +01:00
Oswaldo Ferreira a6c52c4e59 Make merge_jid handling less stateful in MergeService 2017-10-27 22:33:48 +02:00
Sean McGivern ba9b4c4de8 Avoid hitting statement timeout finding MR pipelines
For MRs with many thousands of commits, `SELECT DISTINCT(sha)` will be very
slow.

What we can't do to fix this:

1. Add an index. Postgres won't use it for DISTINCT without a lot of ceremony.
2. Do the `uniq` in Ruby. That can still be very slow with hundreds of
   thousands of commits.
3. Use a subquery. We haven't removed the `st_commits` column yet, but we will
   soon.

Until 3 is available to us, we can just do 2, but also add a limit clause. There
is no ordering, so this may return different results, but our goal with these
MRs is just to get them to load, so it's not a huge deal.
2017-10-27 14:20:55 +01:00
Oswaldo Ferreira b78954c13d Simplify check for running job on Redis 2017-10-13 10:17:41 +02:00
Oswaldo Ferreira 9ab0254085 Make "merge ongoing" check more consistent 2017-10-11 18:48:39 +02:00
Andrew Newdigate 47d19c2de1 Stop using `branch_names.include?` and use `branch_exists?` 2017-10-10 14:56:04 +00:00
Rémy Coutable f070265a6d
Introduce new hook data builders for Issue and MergeRequest
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-10-09 16:44:47 +02:00
Rémy Coutable 075d651604 Start adding Gitlab::HookData::IssuableBuilder
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-10-09 15:07:10 +02:00
Rémy Coutable 67d5ca9f92 Include the changes in issuable webhook payloads
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-10-09 15:07:10 +02:00
Douwe Maan 546b18b903 Merge branch 'tc-geo-read-only-idea' into 'master'
Create idea of read-only database

Closes #37534

See merge request gitlab-org/gitlab-ce!14688
2017-10-07 11:01:21 +00:00
Bob Van Landuyt 70716a1292 Allow creating merge requests across forks of a project 2017-10-07 11:46:23 +02:00
Toon Claes d13669716a Create idea of read-only database
In GitLab EE, a GitLab instance can be read-only (e.g. when it's a Geo
secondary node). But in GitLab CE it also might be useful to have the
"read-only" idea around. So port it back to GitLab CE.

Also having the principle of read-only in GitLab CE would hopefully
lead to less errors introduced, doing write operations when there
aren't allowed for read-only calls.

Closes gitlab-org/gitlab-ce#37534.
2017-10-06 22:37:40 +02:00
Rémy Coutable 67de21c15b Move `fetch_ref` from MergeRequestDiff#ensure_commit_shas to MergeRequest
MergeRequest#create_merge_request_diff and MergeRequest#reload_diff are
the only places where we generate a new MR diff so that's where we
should fetch the ref.

This also ensures that the ref is not fetched when we call
merge_request.merge_request_diffs.create in
Github::Import#fetch_pull_requests.

Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-10-05 10:48:25 +02:00
Sean McGivern b1050bfe39 Merge branch 'merge-request-notes-performance' into 'master'
Use a UNION ALL for getting merge request notes

Closes #38508

See merge request gitlab-org/gitlab-ce!14620
2017-10-04 12:03:32 +00:00
Douwe Maan 2ee93c486c Merge branch '36876-mr-show-json-controller-perf-improvements' into 'master'
Reduce method calls while evaluating Projects::MergeRequestsController#show.json

See merge request gitlab-org/gitlab-ce!14285
2017-10-04 07:33:05 +00:00
Oswaldo Ferreira 1f54c9216f Reduce method calls while evaluating Projects::MergeRequestsController#show.json 2017-10-04 00:09:48 -03:00
Yorick Peterse c16b99a49c
Use a UNION ALL for getting merge request notes
In this particular case the use of UNION ALL leads to a better query
plan compared to using 1 big query that uses an OR statement to combine
different data sources.

See https://gitlab.com/gitlab-org/gitlab-ce/issues/38508 for more
information.
2017-10-02 15:31:59 +02:00
Eric Eastwood 439e3f0735 Port semi-linear merge strategy to CE (mostly FE) 2017-09-29 14:13:35 -05:00
Yorick Peterse 57b96eb6db
Fix refreshing of issues/MR count caches
This ensures the open issues/MR count caches are refreshed properly when
creating new issues or MRs. This MR also includes a change to the cache
keys to ensure all caches are rebuilt on the fly.

This particular problem was not caught in the test suite due to a null
cache being used, resulting in all calls that would use a cache using
the underlying data directly. In production the code would fail because
a newly saved record returns an empty hash in #changes meaning checks
such as `state_changed? || confidential_changed?` would return false for
new rows, thus never updating the counters.

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/38061
2017-09-19 17:16:45 +02:00
Andrew Newdigate 64d7ec0a9e Detect n+1 issues involving Gitaly 2017-09-19 10:55:37 +00:00
micael.bergeron 65bcd141c8 add controller spec
also fix some code styling issues
2017-09-06 09:00:57 -04:00
micael.bergeron b44a1bcd0b rework the contributor badge
- only show in merge-requests
 - show as a little glyph
2017-09-06 09:00:57 -04:00
Sean McGivern e8f29569bc Resolve outdated diff discussions on push 2017-09-06 10:08:03 +01:00
Sean McGivern dabce2c571 Merge branch 'git-operation-service-to-git' into 'master'
Prepare GitOperationService for moving to Gitlab::Git

See merge request !13773
2017-09-04 10:56:26 +00:00
Sean McGivern 2fc500819f Merge branch 'issue_36820' into 'master'
Remove closing external issues by reference error

Closes #36820

See merge request !13910
2017-09-01 09:15:40 +00:00
Felipe Artur 3e4013f217 Remove closing external issues by reference error 2017-08-31 17:15:30 -03:00
Sean McGivern dd406182cb Merge branch 'sidebar-cache-updates' into 'master'
Only update the sidebar count caches when needed

See merge request !13878
2017-08-31 14:30:03 +00:00
Jacob Vosmaer 8ad690b0d4 Prepare GitOperationService for move to Gitlab::Git 2017-08-31 15:35:59 +02:00
Yorick Peterse c158a22fd3
Only update the sidebar count caches when needed
This ensures the issues/MR cache of the sidebar is only updated when the
state or confidential flags changes, instead of changing this for every
update.
2017-08-30 15:49:40 +02:00
Lin Jen-Shin 86149a8216 Merge remote-tracking branch 'upstream/master' into 36807-gc-unwanted-refs-after-import
* upstream/master: (225 commits)
  Add changelog entry
  Backports EE 2756 logic to CE.
  Make rubocop happy
  Make profile settings dropdown consistent
  Add filter by my reaction
  Update spec initialization with it being a shared component
  Update identicon path and selector
  Renamed to `identicon` and make shared component
  Merge branch 'master-i18n' into 'master'
  Fix broken Frontend JS guide
  Replace 'project/star.feature' spinach test with an rspec analog
  Adds position fixed to right sidebar
  Fixes the margin of the top buttons of the pipeline page
  Remove commented out code
  Better align fallback image emojis
  Decrease Metrics/CyclomaticComplexity threshold to 15
  Add changelog
  Respect the default visibility level when creating a group
  Further break with_repo_branch_commit into parts
  Make sure inspect doesn't generate crazy string
  ...
2017-08-30 21:13:19 +08:00
Oswaldo Ferreira ffc576d7df Rename MergeRequest#async_merge to merge_async 2017-08-28 15:55:25 -03:00
Oswaldo Ferreira 9068083f86 Add changelog 2017-08-28 15:48:09 -03:00
Oswaldo Ferreira 4f17c6b763 Track enqueued and ongoing MRs 2017-08-28 15:48:09 -03:00
Oswaldo Ferreira d7f61bae8b Remove locked? check when unlocking a merge request
Our state machine shall have enough knowledge to not allow states other
than locked from transitioning to opened (e.g. MergeRequest#unlock_mr).
2017-08-28 15:48:09 -03:00
Lin Jen-Shin 081e2fce82 Try to make reserved ref names more obvious
So that whenever we want to reserve more, we're aware,
and don't mess it up.
2017-08-25 23:00:06 +08:00
Sean McGivern 7ab4efa8f8 Merge branch '36262_merge_request_reference_in_merge_commit_global' into 'master'
fix Merge request reference in merge commit is not global

Closes #36262

See merge request !13518
2017-08-24 09:09:45 +00:00