Repository navigation
retrieve and cache protected branch information per-repository - #7529
Conversation
|
@shiftkey Please confirm the location of the protected branch data in IndexedDB as I couldn't locate it. Do I have to delete and rebuild the database first? |
|
@tierninho you'll need to drop the database after switching away from this PR (because it increments the version), but check the |
tierninho
left a comment
There was a problem hiding this comment.
Thanks for the DB tips.
Confirming I see the data flowing now when protected branches are enabled in the .com UI. Data remains intact despite deleting the branch in the UI (not remote) 👍
I assume we do not record protected: false for all other branches as that would be cumbersome?
I believe it's a waste to download and store these branches, and the API request excludes these: Line 530 in cf10301 |
niik
left a comment
There was a problem hiding this comment.
Some initial thoughts here before we dive into the code part.
Given that we only care about which branches are protected I wonder if we could simplify the table in the repository database to just be a list of branch names. We could call it protectedBranches instead of gitHubBranches and a record could simply be { repoId: number, name: string }.
Furthermore, since this is going through a pretty time-sensitive path (committing) I think that rather than loading the list of all protected branch names from the database, projecting that list to canonical references, and then checking to see if there's a match we should attempt a primary key retrieval from the database as our check for whether the current branch is protected on the remote or not. I doubt that a primary key lookup would be of any concern from a performance perspective but should it prove to be measurably detrimental to performance we could attempt an in-memory caching layer like what was done in 4ea0bd6.
cf10301 to
502bebc
Compare
|
This is ready for another round of review |
… using upstreamWithoutRemote
Co-Authored-By: Markus Olsson <[email protected]>
e529478 to
e36df6d
Compare
|
|
||
| for (const key of this.branchProtectionCache.keys()) { | ||
| // invalidate any cached entries belonging to this repository | ||
| if (key.startsWith(prefix)) { |
There was a problem hiding this comment.
Ordinarily I'd be hesitant with a linear search here but given that I expect that the number of protected branches will be tiny (i.e. very rarely more than 1 per repository and most of the time none at all) I think this is fine. Even if we 10x our expectations and 10x the average number of repositories this number should still be manageable.
|
@tierninho would you be able to give this another pass today? I'd like to merge this Wednesday morning EST so I can focus on getting #7595 ready for the next beta. |
|
@shiftkey Gave it another pass and the new |

Overview
First part of #7091
Description
This PR lands the work required to retrieve the protected branch and store it in IndexedDB. I'd love some feedback about the table changes made (cc @niik @iAmWillShepherd) to ensure they make sense.
I also wired up a simple check to see if the tracking branch being committed to (they don't need to match up, so I'm deferring to Git rather than trusting the user is following conventions) is found in the list of cached protected branches.
If we're fine with the changes and landing them for 1.7, I'll follow up with subsequent PRs to refine the checks and record metrics to complete #7091.
Release notes
Notes: no-notes