summaryrefslogtreecommitdiff
path: root/app/models/concerns/routable.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42GitLab Bot2022-10-201-0/+3
|
* Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42GitLab Bot2022-05-191-2/+2
|
* Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42GitLab Bot2022-01-201-0/+5
|
* Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42GitLab Bot2021-10-201-1/+2
|
* Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42GitLab Bot2021-05-191-3/+43
|
* Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42GitLab Bot2020-12-171-9/+38
|
* Add latest changes from gitlab-org/gitlab@13-2-stable-eeGitLab Bot2020-07-201-5/+4
|
* Add latest changes from gitlab-org/gitlab@masterGitLab Bot2019-09-261-2/+9
|
* Add latest changes from gitlab-org/gitlab@masterGitLab Bot2019-09-181-2/+2
|
* Add latest changes from gitlab-org/gitlab@masterGitLab Bot2019-09-161-17/+3
|
* Adjust routable metricbjk/routable_counterBen Kochie2019-09-051-8/+4
| | | | | | * Define the counter once. * Make metric name follow Prometheus naming conventions. * Add label for call method.
* Preload routes informationab-routable-nplus1Andreas Brandl2019-09-031-2/+2
| | | | | | | | | | | | | | | | | | | | This fixes a high frequency N+1 issue: `RoutableActions#find_routable!` is used across many controllers to retrieve e.g. the Project or Namespace by path. The `#find_routable!` method calls `#ensure_canonical_path` which in turn retrieves `#full_path` from the given Routable. This in turn triggers a lookup on `routes`, leading to a high frequency of these queries: ```sql SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = $1 AND "routes"."source_type" = $2 LIMIT $3 ``` This is unnecessary as we already join `routes` in `Routable#find_by_full_path` anyways.
* Add another counter to calculate method call ratioab-routable-two-step-searchAndreas Brandl2019-08-301-5/+7
| | | | | | We should see the ratio drop down when enabling the Feature. Recommendation by @andrewn
* Add method call count instrumentationAndreas Brandl2019-08-301-0/+11
|
* Perform two-step Routable lookup by pathAndreas Brandl2019-08-301-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to lookup a Project or Namespace by path, we prefer an exact match (case-sensitive) but in absence of that, we'd also take a case-insensitive match. The case-insensitive matching with preference for the exact match is a bit more involved in SQL as the exact lookup. Yet, the majority of cases will be an exact match. The thinking here is that we can optimize the lookup by performing an exact match first and only if there is no result, we perform the case-insensitive lookup. Data for GitLab.com: * We have about 15M records in routes table * About 2,500 routes exist where there's more than one record with the same `lower(path)` It is possible for a user to craft requests that would always trigger the 2-step search (e.g. we have a route for `/foo/bar`, the request is always for `/FOO/bar`). In this case, the change at hand is not beneficial as it would run an additional query. However, based on the data, it is highly likely that the vast majority of requests can be satisfied with an exact match only. The context for this change is https://gitlab.com/gitlab-org/gitlab-ce/issues/64590#note_208156463.
* Remove dead MySQL codeNick Thomas2019-07-231-37/+6
| | | | None of this code can be reached any more, so it can all be removed
* Upgrade to Rails 5.2upgrade-rails-5-2-ceHeinrich Lee Yu2019-07-121-1/+1
| | | | Updates changed method names and fixes spec failures
* Enable more frozen string in app/models/**/*.rbgfyoung2018-08-071-0/+2
| | | | Partially addresses #47424.
* Remove code for dynamically generating routesstop-dynamic-routable-creationYorick Peterse2018-07-251-42/+2
| | | | | | This adds a database migration that creates routes for any projects and namespaces that don't already have one. We also remove the runtime code for dynamically creating routes, as this is no longer necessary.
* [Rails5] Fix `Route source can't be blank`blackst0ne-rails5-fix-route-source-can-t-be-blankblackst0ne2018-05-111-1/+3
| | | | | | | In Rails 5.0 automatic inverse does not work for polymorphic relathionships. It was fixed in Rails 5.2: https://github.com/rails/rails/pull/28808 Until that the `inverse_of: :source` argument should be set explicitly.
* Resolve "Namespace factory is problematic"Lin Jen-Shin2018-04-231-1/+6
|
* Validate path uniqueness only on Route, and bubble up appropriatelyDouwe Maan2018-02-061-1/+7
|
* Move ModuleWithInstanceVariables to Gitlab namespaceLin Jen-Shin2017-11-221-5/+5
| | | | | And use .rubocop.yml to exclude paths we don't care, rather than using the cop itself to exclude.
* Use StrongMemoize and enable/disable cops properlyLin Jen-Shin2017-11-181-8/+5
|
* Merge remote-tracking branch 'upstream/master' into no-ivar-in-modulesLin Jen-Shin2017-11-061-1/+6
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * upstream/master: (1723 commits) Resolve "Editor icons" Refactor issuable destroy action Ignore routes matching legacy_*_redirect in route specs Gitlab::Git::RevList and LfsChanges use lazy popen Gitlab::Git::Popen can lazily hand output to a block Merge branch 'master-i18n' into 'master' Remove unique validation from external_url in Environment Expose `duration` in Job API entity Add TimeCop freeze for DST and Regular time Harcode project visibility update a changelog Put a condition to old migration that adds fast_forward column to MRs Expose project visibility as CI variable fix flaky tests by removing unneeded clicks and focus actions fix flaky test in gfm_autocomplete_spec.rb Use Gitlab::Git operations for repository mirroring Encapsulate git operations for mirroring in Gitlab::Git Create a Wiki Repository's raw_repository properly Add `Gitlab::Git::Repository#fetch` command Fix Gitlab::Metrics::System#real_time and #monotonic_time doc ...
| * Create idea of read-only databasetc-geo-read-only-ideaToon Claes2017-10-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Redirect to pages daemonZeger-Jan van de Weg2017-10-031-0/+4
| |
* | Allow simple ivar ||= form. Update accordinglyLin Jen-Shin2017-09-191-1/+4
| |
* | Add cop to make sure we don't use ivar in a moduleLin Jen-Shin2017-09-181-0/+1
|/
* Added Cop to blacklist the use of `dependent:`Yorick Peterse2017-07-061-2/+2
| | | | | | | | This is allowed for existing instances so we don't end up 76 offenses right away, but for new code one should _only_ use this if they _have_ to remove non database data. Even then it's usually better to do this in a service class as this gives you more control over how to remove the data (e.g. in bulk).
* Reset @full_path to nil when cache expiresDouglas Barbosa Alexandre2017-07-031-0/+1
|
* Expires full_path cache after project is renamedDouglas Barbosa Alexandre2017-06-291-2/+9
|
* Rebuild the dynamic path before validating itbvl-validate-path-updateBob Van Landuyt2017-06-211-8/+8
| | | | | Otherwise we won't validate updates to the path. Allowing users to change the path to something that's not allowed.
* Use CTEs for nested groups and authorizationsYorick Peterse2017-05-171-83/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix `Routable.find_by_full_path` on MySQLfix-routable-find-by-full-path-on-mysqlSean McGivern2017-05-061-1/+1
|
* Redirect from redirect routes to canonical routesMichael Kozono2017-05-051-4/+20
|
* Cache Routable#full_path in RequestStore to reduce duplicate route loadssh-optimize-duplicate-routable-full-pathStan Hu2017-04-241-2/+13
| | | | | | | | | We see in #27387 that a call to `polymorphic_path` will cause duplicate SELECT route calls for each merge request in a milestone. This happens because calling `project.namespace.becomes(Namespace)` will instantiate a new instance of a Namespace for each merge request, which causes a N+1 query on the routes table. This change caches the state of the route by the specific class and ID, which dramatically eliminates duplicate work.
* use more explicit and explanatory sql statementAlexis Reigel2017-04-061-1/+3
|
* check all groups for 2fa requirementAlexis Reigel2017-04-061-4/+2
|
* add method to get a full routable hierarchyAlexis Reigel2017-04-061-0/+68
|
* Remove repeated routes.path check for postgresql databasemhasbini2017-03-181-4/+6
|
* Store group and project full name and full path in routes tabledz-refactor-full-pathDmitriy Zaporozhets2017-02-081-4/+62
| | | | Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
* Add User#nested_groups and User#nested_projects methodsDmitriy Zaporozhets2017-01-251-0/+15
| | | | Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
* Rename Routable.where_paths_in to Routable.where_full_path_indz-nested-group-improvements-2Dmitriy Zaporozhets2016-12-111-3/+3
| | | | Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
* Validate presence of route by Routable concernDmitriy Zaporozhets2016-12-111-0/+1
| | | | Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
* Add nested groups support on data leveldz-nested-groupsDmitriy Zaporozhets2016-12-081-0/+70
* add parent_id field to namespaces table to store relation with nested groups * create routes table to keep information about full path of every group and project * project/group lookup by full path from routes table Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>