File lock button incorrectly shown in UI when more than 100 files locked in project, due to query limit.
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=495166) </details> <!--IssueSummary end--> ### Summary When a locked file is selected in the repository browser, the lock status is determined by searching for the file in the results from the following query, which is limited to the 101 most recent entries in the `path_locks` table. This means if there are \> 100 locked files in the project, some files will be incorrectly determined as being unlocked, and the Lock button displayed instead of the Unlock button. ``` SELECT "path_locks".* FROM "path_locks" WHERE "path_locks"."project_id" = <project_id> ORDER BY "path_locks"."id" DESC LIMIT 101; ``` This prevents the file from being Unlocked. Reproduced in version 17.3.3. Assumed applicable to gitlab.com. Reported by customer ([ZD internal link](https://gitlab.zendesk.com/agent/tickets/568563)). #### Workaround The **Code, Locked files** page correctly displays all locked files, and allows them to be unlocked. ### Steps to reproduce 1. Create a project `root/file-locking-bug` with 121 files named `files/100.txt` to `files/220.txt` 2. Using the rails console, lock all of the files: ``` include API::Helpers::GraphqlHelpers current_user=User.find_by_username('root') query="mutation toggleLock($projectPath: ID!, $filePath: String!, $lock: Boolean!) { projectSetLocked( input: {projectPath: $projectPath, filePath: $filePath, lock: $lock} ) { project { id pathLocks { nodes { id path __typename } __typename } __typename } errors __typename }}" for i in 100..220 do variables={filePath: "files/#{i}.txt", projectPath: "root/file-locking-bug", lock: true} run_graphql!(query: query, context: {current_user: current_user}, variables: variables) end ``` 3. Go to **Project, Code, Locked files** in the UI and confirm 121 locked files are listed. 4. From the repository browser go to the file `files/220.txt` . Confirm that the Unlock button is displayed, as expected when the file is locked. 5. From the repository browser go to the file `files/100.txt`. Confirm that the Lock button is displayed, despite the file being locked. ### Example Project <!--If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report. If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version.--> ### What is the current _bug_ behavior? Some locked files incorrectly present the Lock button when the file is viewed in the UI. ### What is the expected _correct_ behavior? All locked files should display the Unlock button. ### Relevant logs and/or screenshots ![file-100.png](/uploads/087acbe8d7099868f3cfc83d6c8a3759/file-100.png) ![locked-files.png](/uploads/16c07dee3bb5767283dd65f2c70743ee/locked-files.png) Query run when file 100.txt page refreshed: ``` LOG: execute <unnamed>: /*application:web,correlation_id:01J8RF49NZPWAZC7XV919PC006,endpoint_id:GraphqlController#execute,db_config_name:main*/ SELECT "path_locks".* FROM "path_locks" WHERE "path_locks"."project_id" = 47 ORDER BY "path_locks"."id" DESC LIMIT 101 ``` ### Output of checks <!--If you are reporting a bug on GitLab.com, uncomment below--> <!--This bug happens on GitLab.com--> <!--/label ~"reproduced on GitLab.com"--> #### Results of GitLab environment info <!--Input any relevant GitLab environment information if needed.--> <details> <summary>Expand for output related to GitLab environment info</summary> <pre> (For installations with omnibus-gitlab package run and paste the output of: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`sudo gitlab-rake gitlab:env:info\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`) (For installations from source run and paste the output of: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`) </pre> </details> #### Results of GitLab application Check <!--Input any relevant GitLab application check information if needed.--> <details> <summary>Expand for output related to the GitLab application check</summary> <pre> (For installations with omnibus-gitlab package run and paste the output of: \\\\\\\\\\\\\\\`sudo gitlab-rake gitlab:check SANITIZE=true\\\\\\\\\\\\\\\`) (For installations from source run and paste the output of: \\\\\\\\\\\\\\\`sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true\\\\\\\\\\\\\\\`) (we will only investigate if the tests are passing) </pre> </details> ### Possible fixes <!--If you can, link to the line of code that might be responsible for the problem.-->
issue