-
Notifications
You must be signed in to change notification settings - Fork 4
Contribution defn diffs #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,10 @@ import Share.Web.Share.Contributions.API | |
import Share.Web.Share.Contributions.API qualified as API | ||
import Share.Web.Share.Contributions.Types | ||
import Share.Web.Share.Diffs.Impl qualified as Diffs | ||
import Share.Web.Share.Diffs.Types (ShareNamespaceDiffResponse (..)) | ||
import Share.Web.Share.Diffs.Types (ShareNamespaceDiffResponse (..), ShareTermDiffResponse (..), ShareTypeDiffResponse (..)) | ||
import Share.Web.Share.Types (UserDisplayInfo) | ||
import Unison.Name (Name) | ||
import Unison.Syntax.Name qualified as Name | ||
|
||
contributionsByProjectServer :: Maybe Session -> UserHandle -> ProjectSlug -> ServerT API.ContributionsByProjectAPI WebApp | ||
contributionsByProjectServer session handle projectSlug = | ||
|
@@ -62,7 +64,10 @@ contributionsByProjectServer session handle projectSlug = | |
addServerTag (Proxy @API.ContributionResourceServer) "contribution-number" (IDs.toText contributionNumber) $ | ||
getContributionByNumberEndpoint session handle projectSlug contributionNumber | ||
:<|> updateContributionByNumberEndpoint session handle projectSlug contributionNumber | ||
:<|> contributionDiffEndpoint session handle projectSlug contributionNumber | ||
:<|> ( contributionDiffTermsEndpoint session handle projectSlug contributionNumber | ||
:<|> contributionDiffTypesEndpoint session handle projectSlug contributionNumber | ||
:<|> contributionDiffEndpoint session handle projectSlug contributionNumber | ||
) | ||
:<|> mergeContributionEndpoint session handle projectSlug contributionNumber | ||
:<|> timelineServer contributionNumber | ||
in listContributionsByProjectEndpoint session handle projectSlug | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
Caching.cachedResponse authZReceipt "contribution-diff" cacheKeys do | ||
let oldCausalId = fromMaybe oldBranchCausalId bestCommonAncestorCausalId | ||
namespaceDiff <- Diffs.diffCausals authZReceipt oldCausalId newBranchCausalId | ||
(newBranchCausalHash, oldCausalHash) <- PG.runTransaction $ do | ||
newBranchCausalHash <- CausalQ.expectCausalHashesByIdsOf id newBranchCausalId | ||
|
@@ -255,6 +260,96 @@ contributionDiffEndpoint (AuthN.MaybeAuthedUserID mayCallerUserId) userHandle pr | |
where | ||
projectShorthand = IDs.ProjectShortHand {userHandle, projectSlug} | ||
|
||
contributionDiffTermsEndpoint :: | ||
Maybe Session -> | ||
UserHandle -> | ||
ProjectSlug -> | ||
IDs.ContributionNumber -> | ||
Name -> | ||
Name -> | ||
WebApp (Cached JSON ShareTermDiffResponse) | ||
contributionDiffTermsEndpoint (AuthN.MaybeAuthedUserID mayCallerUserId) userHandle projectSlug contributionNumber oldTermName newTermName = | ||
do | ||
( project, | ||
Contribution {contributionId, bestCommonAncestorCausalId}, | ||
oldBranch@Branch {causal = oldBranchCausalId, branchId = oldBranchId}, | ||
newBranch@Branch {causal = newBranchCausalId, branchId = newBranchId} | ||
) <- PG.runTransactionOrRespondError $ do | ||
project@Project {projectId} <- Q.projectByShortHand projectShorthand `whenNothingM` throwError (EntityMissing (ErrorID "project:missing") "Project not found") | ||
contribution@Contribution {sourceBranchId = newBranchId, targetBranchId = oldBranchId} <- ContributionsQ.contributionByProjectIdAndNumber projectId contributionNumber `whenNothingM` throwError (EntityMissing (ErrorID "contribution:missing") "Contribution not found") | ||
newBranch <- Q.branchById newBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Source branch not found") | ||
oldBranch <- Q.branchById oldBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Target branch not found") | ||
pure (project, contribution, oldBranch, newBranch) | ||
authZReceipt <- AuthZ.permissionGuard $ AuthZ.checkContributionRead mayCallerUserId project | ||
let oldCodebase = Codebase.codebaseForProjectBranch authZReceipt project oldBranch | ||
let newCodebase = Codebase.codebaseForProjectBranch authZReceipt project newBranch | ||
oldPBSH <- Codebase.runCodebaseTransactionOrRespondError oldCodebase $ do | ||
lift $ Q.projectBranchShortHandByBranchId oldBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Target branch not found") | ||
newPBSH <- Codebase.runCodebaseTransactionOrRespondError newCodebase $ do | ||
lift $ Q.projectBranchShortHandByBranchId newBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Source branch not found") | ||
let oldCausalId = fromMaybe oldBranchCausalId bestCommonAncestorCausalId | ||
let cacheKeys = [IDs.toText contributionId, IDs.toText newPBSH, IDs.toText oldPBSH, Caching.causalIdCacheKey newBranchCausalId, Caching.causalIdCacheKey oldCausalId, Name.toText oldTermName, Name.toText newTermName] | ||
Caching.cachedResponse authZReceipt "contribution-diff-terms" cacheKeys do | ||
(oldBranchHashId, newBranchHashId) <- PG.runTransaction $ CausalQ.expectNamespaceIdsByCausalIdsOf both (oldCausalId, newBranchCausalId) | ||
(oldTerm, newTerm, displayObjDiff) <- Diffs.diffTerms authZReceipt (oldCodebase, oldBranchHashId, oldTermName) (newCodebase, newBranchHashId, newTermName) | ||
pure $ | ||
ShareTermDiffResponse | ||
{ project = projectShorthand, | ||
oldBranch = IDs.IsBranchShortHand $ IDs.projectBranchShortHandToBranchShortHand oldPBSH, | ||
newBranch = IDs.IsBranchShortHand $ IDs.projectBranchShortHandToBranchShortHand newPBSH, | ||
oldTerm = oldTerm, | ||
newTerm = newTerm, | ||
diff = displayObjDiff | ||
} | ||
where | ||
projectShorthand :: IDs.ProjectShortHand | ||
projectShorthand = IDs.ProjectShortHand {userHandle, projectSlug} | ||
|
||
contributionDiffTypesEndpoint :: | ||
Maybe Session -> | ||
UserHandle -> | ||
ProjectSlug -> | ||
IDs.ContributionNumber -> | ||
Name -> | ||
Name -> | ||
WebApp (Cached JSON ShareTypeDiffResponse) | ||
contributionDiffTypesEndpoint (AuthN.MaybeAuthedUserID mayCallerUserId) userHandle projectSlug contributionNumber oldTypeName newTypeName = | ||
do | ||
( project, | ||
Contribution {contributionId, bestCommonAncestorCausalId}, | ||
oldBranch@Branch {causal = oldBranchCausalId, branchId = oldBranchId}, | ||
newBranch@Branch {causal = newBranchCausalId, branchId = newBranchId} | ||
) <- PG.runTransactionOrRespondError $ do | ||
project@Project {projectId} <- Q.projectByShortHand projectShorthand `whenNothingM` throwError (EntityMissing (ErrorID "project:missing") "Project not found") | ||
contribution@Contribution {sourceBranchId = newBranchId, targetBranchId = oldBranchId} <- ContributionsQ.contributionByProjectIdAndNumber projectId contributionNumber `whenNothingM` throwError (EntityMissing (ErrorID "contribution:missing") "Contribution not found") | ||
newBranch <- Q.branchById newBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Source branch not found") | ||
oldBranch <- Q.branchById oldBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Target branch not found") | ||
pure (project, contribution, oldBranch, newBranch) | ||
authZReceipt <- AuthZ.permissionGuard $ AuthZ.checkContributionRead mayCallerUserId project | ||
let oldCodebase = Codebase.codebaseForProjectBranch authZReceipt project oldBranch | ||
let newCodebase = Codebase.codebaseForProjectBranch authZReceipt project newBranch | ||
oldPBSH <- Codebase.runCodebaseTransactionOrRespondError oldCodebase $ do | ||
lift $ Q.projectBranchShortHandByBranchId oldBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Target branch not found") | ||
newPBSH <- Codebase.runCodebaseTransactionOrRespondError newCodebase $ do | ||
lift $ Q.projectBranchShortHandByBranchId newBranchId `whenNothingM` throwError (EntityMissing (ErrorID "branch:missing") "Source branch not found") | ||
let oldCausalId = fromMaybe oldBranchCausalId bestCommonAncestorCausalId | ||
let cacheKeys = [IDs.toText contributionId, IDs.toText newPBSH, IDs.toText oldPBSH, Caching.causalIdCacheKey newBranchCausalId, Caching.causalIdCacheKey oldCausalId, Name.toText oldTypeName, Name.toText newTypeName] | ||
Caching.cachedResponse authZReceipt "contribution-diff-types" cacheKeys do | ||
(oldBranchHashId, newBranchHashId) <- PG.runTransaction $ CausalQ.expectNamespaceIdsByCausalIdsOf both (oldCausalId, newBranchCausalId) | ||
(oldType, newType, displayObjDiff) <- Diffs.diffTypes authZReceipt (oldCodebase, oldBranchHashId, oldTypeName) (newCodebase, newBranchHashId, newTypeName) | ||
pure $ | ||
ShareTypeDiffResponse | ||
{ project = projectShorthand, | ||
oldBranch = IDs.IsBranchShortHand $ IDs.projectBranchShortHandToBranchShortHand oldPBSH, | ||
newBranch = IDs.IsBranchShortHand $ IDs.projectBranchShortHandToBranchShortHand newPBSH, | ||
oldType = oldType, | ||
newType = newType, | ||
diff = displayObjDiff | ||
} | ||
where | ||
projectShorthand :: IDs.ProjectShortHand | ||
projectShorthand = IDs.ProjectShortHand {userHandle, projectSlug} | ||
|
||
mergeContributionEndpoint :: | ||
Maybe Session -> | ||
UserHandle -> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.