<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/gitlab/gitlab-ce.git/spec/requests/api/groups_spec.rb, branch bugfix/upgrade-ruby-parser</title>
<subtitle>gitlab.com: gitlab-org/gitlab-ce.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/'/>
<entry>
<title>Use CTEs for nested groups and authorizations</title>
<updated>2017-05-17T14:51:08+00:00</updated>
<author>
<name>Yorick Peterse</name>
<email>yorickpeterse@gmail.com</email>
</author>
<published>2017-04-24T15:19:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=ac382b5682dc2d5eea750313c59fb2581af13326'/>
<id>ac382b5682dc2d5eea750313c59fb2581af13326</id>
<content type='text'>
This commit introduces the usage of Common Table Expressions (CTEs) to
efficiently retrieve nested group hierarchies, without having to rely on
the "routes" table (which is an _incredibly_ inefficient way of getting
the data). This requires a patch to ActiveRecord (found in the added
initializer) to work properly as ActiveRecord doesn't support WITH
statements properly out of the box.

Unfortunately MySQL provides no efficient way of getting nested groups.
For example, the old routes setup could easily take 5-10 seconds
depending on the amount of "routes" in a database. Providing vastly
different logic for both MySQL and PostgreSQL will negatively impact the
development process. Because of this the various nested groups related
methods return empty relations when used in combination with MySQL.

For project authorizations the logic is split up into two classes:

* Gitlab::ProjectAuthorizations::WithNestedGroups
* Gitlab::ProjectAuthorizations::WithoutNestedGroups

Both classes get the fresh project authorizations (= as they should be
in the "project_authorizations" table), including nested groups if
PostgreSQL is used. The logic of these two classes is quite different
apart from their public interface. This complicates development a bit,
but unfortunately there is no way around this.

This commit also introduces Gitlab::GroupHierarchy. This class can be
used to get the ancestors and descendants of a base relation, or both by
using a UNION. This in turn is used by methods such as:

* Namespace#ancestors
* Namespace#descendants
* User#all_expanded_groups

Again this class relies on CTEs and thus only works on PostgreSQL. The
Namespace methods will return an empty relation when MySQL is used,
while User#all_expanded_groups will return only the groups a user is a
direct member of.

Performance wise the impact is quite large. For example, on GitLab.com
Namespace#descendants used to take around 580 ms to retrieve data for a
particular user. Using CTEs we are able to reduce this down to roughly 1
millisecond, returning the exact same data.

== On The Fly Refreshing

Refreshing of authorizations on the fly (= when
users.authorized_projects_populated was not set) is removed with this
commit. This simplifies the code, and ensures any queries used for
authorizations are not mutated because they are executed in a Rails
scope (e.g. Project.visible_to_user).

This commit includes a migration to schedule refreshing authorizations
for all users, ensuring all of them have their authorizations in place.
Said migration schedules users in batches of 5000, with 5 minutes
between every batch to smear the load around a bit.

== Spec Changes

This commit also introduces some changes to various specs. For example,
some specs for ProjectTeam assumed that creating a personal project
would _not_ lead to the owner having access, which is incorrect. Because
we also no longer refresh authorizations on the fly for new users some
code had to be added to the "empty_project" factory. This chunk of code
ensures that the owner's permissions are refreshed after creating the
project, something that is normally done in Projects::CreateService.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This commit introduces the usage of Common Table Expressions (CTEs) to
efficiently retrieve nested group hierarchies, without having to rely on
the "routes" table (which is an _incredibly_ inefficient way of getting
the data). This requires a patch to ActiveRecord (found in the added
initializer) to work properly as ActiveRecord doesn't support WITH
statements properly out of the box.

Unfortunately MySQL provides no efficient way of getting nested groups.
For example, the old routes setup could easily take 5-10 seconds
depending on the amount of "routes" in a database. Providing vastly
different logic for both MySQL and PostgreSQL will negatively impact the
development process. Because of this the various nested groups related
methods return empty relations when used in combination with MySQL.

For project authorizations the logic is split up into two classes:

* Gitlab::ProjectAuthorizations::WithNestedGroups
* Gitlab::ProjectAuthorizations::WithoutNestedGroups

Both classes get the fresh project authorizations (= as they should be
in the "project_authorizations" table), including nested groups if
PostgreSQL is used. The logic of these two classes is quite different
apart from their public interface. This complicates development a bit,
but unfortunately there is no way around this.

This commit also introduces Gitlab::GroupHierarchy. This class can be
used to get the ancestors and descendants of a base relation, or both by
using a UNION. This in turn is used by methods such as:

* Namespace#ancestors
* Namespace#descendants
* User#all_expanded_groups

Again this class relies on CTEs and thus only works on PostgreSQL. The
Namespace methods will return an empty relation when MySQL is used,
while User#all_expanded_groups will return only the groups a user is a
direct member of.

Performance wise the impact is quite large. For example, on GitLab.com
Namespace#descendants used to take around 580 ms to retrieve data for a
particular user. Using CTEs we are able to reduce this down to roughly 1
millisecond, returning the exact same data.

== On The Fly Refreshing

Refreshing of authorizations on the fly (= when
users.authorized_projects_populated was not set) is removed with this
commit. This simplifies the code, and ensures any queries used for
authorizations are not mutated because they are executed in a Rails
scope (e.g. Project.visible_to_user).

This commit includes a migration to schedule refreshing authorizations
for all users, ensuring all of them have their authorizations in place.
Said migration schedules users in batches of 5000, with 5 minutes
between every batch to smear the load around a bit.

== Spec Changes

This commit also introduces some changes to various specs. For example,
some specs for ProjectTeam assumed that creating a personal project
would _not_ lead to the owner having access, which is incorrect. Because
we also no longer refresh authorizations on the fly for new users some
code had to be added to the "empty_project" factory. This chunk of code
ensures that the owner's permissions are refreshed after creating the
project, something that is normally done in Projects::CreateService.
</pre>
</div>
</content>
</entry>
<entry>
<title>Enable the Style/TrailingCommaInLiteral cop</title>
<updated>2017-05-10T16:25:45+00:00</updated>
<author>
<name>Rémy Coutable</name>
<email>remy@rymai.me</email>
</author>
<published>2017-05-03T11:22:03+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=d40e1f547ea9e31e822229bb808aaa6b9201f473'/>
<id>d40e1f547ea9e31e822229bb808aaa6b9201f473</id>
<content type='text'>
Use the EnforcedStyleForMultiline: no_comma option.

Signed-off-by: Rémy Coutable &lt;remy@rymai.me&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Use the EnforcedStyleForMultiline: no_comma option.

Signed-off-by: Rémy Coutable &lt;remy@rymai.me&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Use relative paths for group/project/user avatars</title>
<updated>2017-05-10T04:26:17+00:00</updated>
<author>
<name>blackst0ne</name>
<email>blackst0ne.ru@gmail.com</email>
</author>
<published>2017-05-10T04:26:17+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=29a3203b3fe08649b80def65b7750a866454d3d6'/>
<id>29a3203b3fe08649b80def65b7750a866454d3d6</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Unnecessary "include WaitForAjax" and "include ApiHelpers"</title>
<updated>2017-04-21T20:32:02+00:00</updated>
<author>
<name>Jacopo</name>
<email>beschi.jacopo@gmail.com</email>
</author>
<published>2017-04-21T20:32:02+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=ff76adb5476f663fe92cec0ec4a78e93c7615191'/>
<id>ff76adb5476f663fe92cec0ec4a78e93c7615191</id>
<content type='text'>
Removed all the unnecessary include of `WaitForAjax` and `ApiHelpers` in the specs.
Removed unnecessary usage of `api:true`
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Removed all the unnecessary include of `WaitForAjax` and `ApiHelpers` in the specs.
Removed unnecessary usage of `api:true`
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix all tests</title>
<updated>2017-03-06T13:34:07+00:00</updated>
<author>
<name>Toon Claes</name>
<email>toon@gitlab.com</email>
</author>
<published>2017-03-03T15:39:29+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=9e942b59720a4e22a16f71de66a8cf4706f3c92b'/>
<id>9e942b59720a4e22a16f71de66a8cf4706f3c92b</id>
<content type='text'>
This commit was about 6 commits before squashing, with the main goal to
make all tests green. Now, after pushing this commit we'll see what the
CI has to say about that.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This commit was about 6 commits before squashing, with the main goal to
make all tests green. Now, after pushing this commit we'll see what the
CI has to say about that.
</pre>
</div>
</content>
</entry>
<entry>
<title>Update entities, rename from builds to jobs</title>
<updated>2017-03-06T13:34:07+00:00</updated>
<author>
<name>Z.J. van de Weg</name>
<email>git@zjvandeweg.nl</email>
</author>
<published>2017-02-23T08:16:20+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=b5b93f80e57437163c45f8fef056a2a0b58e643e'/>
<id>b5b93f80e57437163c45f8fef056a2a0b58e643e</id>
<content type='text'>
This commit only renames the commits, the cascading effects will be
dealt with later.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This commit only renames the commits, the cascading effects will be
dealt with later.
</pre>
</div>
</content>
</entry>
<entry>
<title>Expose Group VisibilityLevel as String</title>
<updated>2017-03-02T11:15:24+00:00</updated>
<author>
<name>Toon Claes</name>
<email>toon@gitlab.com</email>
</author>
<published>2017-02-16T13:56:14+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=f45cbc87015dd2e6369e758ca96132cb44c8983a'/>
<id>f45cbc87015dd2e6369e758ca96132cb44c8983a</id>
<content type='text'>
Instead of exposing the VisibilityLevel as Integer, expose it as
String `visibility`.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Instead of exposing the VisibilityLevel as Integer, expose it as
String `visibility`.
</pre>
</div>
</content>
</entry>
<entry>
<title>Return 204 for delete endpoints</title>
<updated>2017-02-28T07:32:38+00:00</updated>
<author>
<name>Robert Schilling</name>
<email>rschilling@student.tugraz.at</email>
</author>
<published>2017-02-20T18:18:12+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=86c58687b22f788ad7c821af55abece2f9d89d50'/>
<id>86c58687b22f788ad7c821af55abece2f9d89d50</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'dm-more-namespace-full-path' into 'master'</title>
<updated>2017-02-24T15:39:12+00:00</updated>
<author>
<name>Sean McGivern</name>
<email>sean@mcgivern.me.uk</email>
</author>
<published>2017-02-24T15:39:12+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=faaca5e191f9fe3894ad7587b42495fcbcab9328'/>
<id>faaca5e191f9fe3894ad7587b42495fcbcab9328</id>
<content type='text'>

Use Namespace#full_path instead of #path where appropriate

See merge request !9495</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>

Use Namespace#full_path instead of #path where appropriate

See merge request !9495</pre>
</div>
</content>
</entry>
<entry>
<title>API: Use parameter to get owned groups instead of dedicated endpoint</title>
<updated>2017-02-24T09:31:41+00:00</updated>
<author>
<name>Robert Schilling</name>
<email>rschilling@student.tugraz.at</email>
</author>
<published>2017-02-24T08:25:53+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gitlab/gitlab-ce.git/commit/?id=161500366561297626ca6df76fb68beb846d5249'/>
<id>161500366561297626ca6df76fb68beb846d5249</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
