Skip to content

retrieve and cache protected branch information per-repository - #7529

Merged
niik merged 20 commits into
developmentfrom
shiftkey/store-branch-information-for-repository
May 22, 2019
Merged

niik merged 20 commits into
developmentfrom
shiftkey/store-branch-information-for-repository

Conversation

@shiftkey

Copy link
Copy Markdown
Member

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

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label May 14, 2019
@shiftkey shiftkey added this to the 1.7.0 milestone May 14, 2019
@tierninho

Copy link
Copy Markdown
Contributor

@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?

@shiftkey

Copy link
Copy Markdown
Member Author

@tierninho you'll need to drop the database after switching away from this PR (because it increments the version), but check the IndexedDB -> Database -> githubBranches table for entries:

@tierninho
tierninho self-requested a review May 14, 2019 19:22
tierninho
tierninho previously approved these changes May 14, 2019

@tierninho tierninho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@shiftkey

Copy link
Copy Markdown
Member Author

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:

const path = `repos/${owner}/${name}/branches?protected=true`

@niik niik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@shiftkey
shiftkey force-pushed the shiftkey/store-branch-information-for-repository branch from cf10301 to 502bebc Compare May 20, 2019 18:51
@shiftkey
shiftkey requested a review from niik May 20, 2019 19:13
@shiftkey

Copy link
Copy Markdown
Member Author

This is ready for another round of review

Comment thread app/src/lib/stores/app-store.ts Resolved
Comment thread app/src/lib/stores/app-store.ts Resolved
Comment thread app/src/lib/api.ts Resolved
@shiftkey
shiftkey force-pushed the shiftkey/store-branch-information-for-repository branch from e529478 to e36df6d Compare May 21, 2019 11:51
@shiftkey
shiftkey requested a review from niik May 21, 2019 12:48

for (const key of this.branchProtectionCache.keys()) {
// invalidate any cached entries belonging to this repository
if (key.startsWith(prefix)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@shiftkey

Copy link
Copy Markdown
Member Author

@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.

@tierninho

Copy link
Copy Markdown
Contributor

@shiftkey Gave it another pass and the new protectedBranches table is reflected with all the protected branches matching up between remote and local. 👍

@niik
niik merged commit bee4c6b into development May 22, 2019
@shiftkey
shiftkey deleted the shiftkey/store-branch-information-for-repository branch June 14, 2019 16:49
@outofambit outofambit added the metrics measuring user behavior for better decisions label Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

metrics measuring user behavior for better decisions ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants