Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribution defn diffs #15

Merged
merged 3 commits into from
Jul 29, 2024
Merged

Contribution defn diffs #15

merged 3 commits into from
Jul 29, 2024

Conversation

ChrisPenner
Copy link
Contributor

Overview

A small wrapper around the existing term and type diff apis which is scoped to contributions. This will allow us to use the best common ancestor for definition diffs, solving the bug we have where the diff of a PR changes unexpected when it's merged.

Implementation

Adds two new endpoints:

  • /users/<handle>/projects/<slug>/contributions/<n>/diff/terms?oldTerm=old.name&newTerm=new.name
  • /users/<handle>/projects/<slug>/contributions/<n>/diff/terms?oldType=old.name&newType=new.name

These behave identically to the existing definition diff endpoints except that they use the best-common-ancestor that's saved on the contribution as the diff base.

Comment on lines -17 to -18
loadNamespaceIdForCausal,
expectNamespaceIdForCausal,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These don't fit the new traversal loader pattern, and already had a replacement, so I replaced all usages of these.

@@ -235,9 +240,9 @@ contributionDiffEndpoint (AuthN.MaybeAuthedUserID mayCallerUserId) userHandle pr
newPBSH <- Codebase.runCodebaseTransactionOrRespondError newCodebase $ do
lift $ Q.projectBranchShortHandByBranchId newBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Source branch not found")

let cacheKeys = [IDs.toText contributionId, IDs.toText newPBSH, IDs.toText oldPBSH, Caching.causalIdCacheKey newBranchCausalId, Caching.causalIdCacheKey oldBranchCausalId]
let oldCausalId = fromMaybe oldBranchCausalId bestCommonAncestorCausalId
let cacheKeys = [IDs.toText contributionId, IDs.toText newPBSH, IDs.toText oldPBSH, Caching.causalIdCacheKey newBranchCausalId, Caching.causalIdCacheKey oldCausalId]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I altered the caching key to use the BCA so the cache will blow less often (but will still be correct)

@ChrisPenner ChrisPenner requested a review from hojberg July 29, 2024 21:21
@ChrisPenner ChrisPenner merged commit 0aeb41d into main Jul 29, 2024
4 checks passed
@ChrisPenner ChrisPenner deleted the cp/contribution-defn-diffs branch July 29, 2024 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant