chore(server): core IoC 16 - getSpecificBranchCommitsFactory
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
||||
import {
|
||||
getAllBranchCommits,
|
||||
getCommitsAndTheirBranchIds,
|
||||
getSpecificBranchCommits
|
||||
getSpecificBranchCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getStreamObjects } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
@@ -68,7 +68,7 @@ export async function addCommentCreatedActivity(params: {
|
||||
getStreamObjects,
|
||||
getBranchLatestCommits: getBranchLatestCommitsFactory({ db }),
|
||||
getStreamBranchesByName: getStreamBranchesByNameFactory({ db }),
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommits: getSpecificBranchCommitsFactory({ db }),
|
||||
getAllBranchCommits
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
} from '@/modules/core/services/commit/viewerResources'
|
||||
import {
|
||||
getAllBranchCommits,
|
||||
getSpecificBranchCommits
|
||||
getSpecificBranchCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import {
|
||||
getCommentFactory,
|
||||
@@ -90,7 +90,7 @@ const command: CommandModule<
|
||||
getStreamObjects,
|
||||
getBranchLatestCommits,
|
||||
getStreamBranchesByName: getStreamBranchesByNameFactory({ db }),
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommits: getSpecificBranchCommitsFactory({ db }),
|
||||
getAllBranchCommits
|
||||
})
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
} from '@/modules/activitystream/services/commentActivity'
|
||||
import {
|
||||
getAllBranchCommits,
|
||||
getSpecificBranchCommits
|
||||
getSpecificBranchCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import {
|
||||
getViewerResourceGroupsFactory,
|
||||
@@ -87,7 +87,7 @@ const command: CommandModule<
|
||||
getStreamObjects,
|
||||
getBranchLatestCommits: getBranchLatestCommitsFactory({ db }),
|
||||
getStreamBranchesByName: getStreamBranchesByNameFactory({ db }),
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommits: getSpecificBranchCommitsFactory({ db }),
|
||||
getAllBranchCommits
|
||||
})
|
||||
})
|
||||
|
||||
@@ -88,7 +88,7 @@ import { ResourceIdentifier } from '@/modules/comments/domain/types'
|
||||
import {
|
||||
getAllBranchCommits,
|
||||
getCommitsAndTheirBranchIds,
|
||||
getSpecificBranchCommits
|
||||
getSpecificBranchCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getStreamObjects } from '@/modules/core/repositories/objects'
|
||||
import { adminOverrideEnabled } from '@/modules/shared/helpers/envHelper'
|
||||
@@ -178,7 +178,7 @@ const getViewerResourceItemsUngrouped = getViewerResourceItemsUngroupedFactory({
|
||||
getStreamObjects,
|
||||
getBranchLatestCommits: getBranchLatestCommitsFactory({ db }),
|
||||
getStreamBranchesByName: getStreamBranchesByNameFactory({ db }),
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommits: getSpecificBranchCommitsFactory({ db }),
|
||||
getAllBranchCommits
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { CommitWithStreamBranchMetadata } from '@/modules/core/domain/commits/types'
|
||||
import {
|
||||
BranchCommit,
|
||||
CommitWithStreamBranchMetadata
|
||||
} from '@/modules/core/domain/commits/types'
|
||||
import { Optional } from '@speckle/shared'
|
||||
|
||||
export type GetCommits = (
|
||||
@@ -21,3 +24,10 @@ export type DeleteCommitAndNotify = (
|
||||
streamId: string,
|
||||
userId: string
|
||||
) => Promise<boolean>
|
||||
|
||||
export type GetSpecificBranchCommits = (
|
||||
pairs: {
|
||||
branchId: string
|
||||
commitId: string
|
||||
}[]
|
||||
) => Promise<BranchCommit[]>
|
||||
|
||||
@@ -4,6 +4,7 @@ export type Commit = CommitRecord
|
||||
export type BranchLatestCommit = Commit & {
|
||||
branchId: string
|
||||
}
|
||||
export type BranchCommit = BranchLatestCommit
|
||||
|
||||
export type CommitWithStreamBranchMetadata = Commit & {
|
||||
streamId: string
|
||||
|
||||
@@ -42,7 +42,7 @@ import { CommitNotFoundError } from '@/modules/core/errors/commit'
|
||||
import { getStreamObjects } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
getAllBranchCommits,
|
||||
getSpecificBranchCommits
|
||||
getSpecificBranchCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { db } from '@/db/knex'
|
||||
import {
|
||||
@@ -57,7 +57,7 @@ const getViewerResourceGroups = getViewerResourceGroupsFactory({
|
||||
getStreamObjects,
|
||||
getBranchLatestCommits: getBranchLatestCommitsFactory({ db }),
|
||||
getStreamBranchesByName: getStreamBranchesByNameFactory({ db }),
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommits: getSpecificBranchCommitsFactory({ db }),
|
||||
getAllBranchCommits
|
||||
})
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import { ServerInviteRecord } from '@/modules/serverinvites/domain/types'
|
||||
import {
|
||||
getCommitBranches,
|
||||
getCommitsFactory,
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommitsFactory,
|
||||
getStreamCommitCounts,
|
||||
getUserAuthoredCommitCounts,
|
||||
getUserStreamCommitCounts
|
||||
@@ -111,6 +111,7 @@ const getBranchLatestCommits = getBranchLatestCommitsFactory({ db })
|
||||
const getStreamBranchCounts = getStreamBranchCountsFactory({ db })
|
||||
const getBranchCommitCounts = getBranchCommitCountsFactory({ db })
|
||||
const getCommits = getCommitsFactory({ db })
|
||||
const getSpecificBranchCommits = getSpecificBranchCommitsFactory({ db })
|
||||
|
||||
/**
|
||||
* TODO: Lazy load DataLoaders to reduce memory usage
|
||||
|
||||
@@ -26,7 +26,8 @@ import {
|
||||
DeleteCommit,
|
||||
DeleteCommits,
|
||||
GetCommit,
|
||||
GetCommits
|
||||
GetCommits,
|
||||
GetSpecificBranchCommits
|
||||
} from '@/modules/core/domain/commits/operations'
|
||||
|
||||
const tables = {
|
||||
@@ -115,20 +116,6 @@ export const deleteCommitFactory =
|
||||
return !!delCount
|
||||
}
|
||||
|
||||
export async function getStreamCommitsWithBranchId(streamId: string) {
|
||||
const baseQuery = Commits.knex<CommitRecord[]>()
|
||||
.select<Array<CommitRecord & { branchId: string }>>([
|
||||
...Commits.cols,
|
||||
BranchCommits.col.branchId
|
||||
])
|
||||
.innerJoin(StreamCommits.name, StreamCommits.col.commitId, Commits.col.id)
|
||||
.innerJoin(BranchCommits.name, BranchCommits.col.commitId, Commits.col.id)
|
||||
.where(StreamCommits.col.streamId, streamId)
|
||||
.orderBy(Commits.col.createdAt)
|
||||
|
||||
return await baseQuery
|
||||
}
|
||||
|
||||
export function getBatchedStreamCommits(
|
||||
streamId: string,
|
||||
options?: Partial<BatchedSelectOptions>
|
||||
@@ -228,37 +215,38 @@ export async function getCommitsAndTheirBranchIds(commitIds: string[]) {
|
||||
.whereIn(Commits.col.id, commitIds)
|
||||
}
|
||||
|
||||
export async function getSpecificBranchCommits(
|
||||
pairs: { branchId: string; commitId: string }[]
|
||||
) {
|
||||
if (!pairs?.length) return []
|
||||
export const getSpecificBranchCommitsFactory =
|
||||
(deps: { db: Knex }): GetSpecificBranchCommits =>
|
||||
async (pairs: { branchId: string; commitId: string }[]) => {
|
||||
if (!pairs?.length) return []
|
||||
|
||||
const commitIds = uniq(pairs.map((p) => p.commitId))
|
||||
const branchIds = uniq(pairs.map((p) => p.branchId))
|
||||
const commitIds = uniq(pairs.map((p) => p.commitId))
|
||||
const branchIds = uniq(pairs.map((p) => p.branchId))
|
||||
|
||||
const q = Commits.knex()
|
||||
.select<Array<CommitRecord & { branchId: string }>>([
|
||||
...Commits.cols,
|
||||
BranchCommits.col.branchId
|
||||
])
|
||||
.innerJoin(BranchCommits.name, BranchCommits.col.commitId, Commits.col.id)
|
||||
.whereIn(Commits.col.id, commitIds)
|
||||
.whereIn(BranchCommits.col.branchId, branchIds)
|
||||
const q = tables
|
||||
.commits(deps.db)
|
||||
.select<Array<CommitRecord & { branchId: string }>>([
|
||||
...Commits.cols,
|
||||
BranchCommits.col.branchId
|
||||
])
|
||||
.innerJoin(BranchCommits.name, BranchCommits.col.commitId, Commits.col.id)
|
||||
.whereIn(Commits.col.id, commitIds)
|
||||
.whereIn(BranchCommits.col.branchId, branchIds)
|
||||
|
||||
const queryResults = await q
|
||||
const results: Array<CommitRecord & { branchId: string }> = []
|
||||
const queryResults = await q
|
||||
const results: Array<CommitRecord & { branchId: string }> = []
|
||||
|
||||
for (const pair of pairs) {
|
||||
const commit = queryResults.find(
|
||||
(r) => r.id === pair.commitId && r.branchId === pair.branchId
|
||||
)
|
||||
if (commit) {
|
||||
results.push(commit)
|
||||
for (const pair of pairs) {
|
||||
const commit = queryResults.find(
|
||||
(r) => r.id === pair.commitId && r.branchId === pair.branchId
|
||||
)
|
||||
if (commit) {
|
||||
results.push(commit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
export type PaginatedBranchCommitsBaseParams = {
|
||||
branchId: string
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
import {
|
||||
getBranchCommitsTotalCount,
|
||||
getPaginatedBranchCommits as getPaginatedBranchCommitsDb,
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommitsFactory,
|
||||
PaginatedBranchCommitsParams
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import {
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
getCommitsTotalCountByStreamId
|
||||
} from '@/modules/core/services/commits'
|
||||
import { BadRequestError } from '@/modules/shared/errors'
|
||||
import { db } from '@/db/knex'
|
||||
|
||||
export async function getPaginatedStreamCommits(
|
||||
streamId: string,
|
||||
@@ -45,6 +46,8 @@ export async function getPaginatedBranchCommits(
|
||||
'Cannot return more than 100 items, please use pagination.'
|
||||
)
|
||||
|
||||
const getSpecificBranchCommits = getSpecificBranchCommitsFactory({ db })
|
||||
|
||||
// Load priority commits first
|
||||
let priorityCommitPromise: Optional<ReturnType<typeof getSpecificBranchCommits>> =
|
||||
undefined
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
GetBranchLatestCommits,
|
||||
GetStreamBranchesByName
|
||||
} from '@/modules/core/domain/branches/operations'
|
||||
import { GetSpecificBranchCommits } from '@/modules/core/domain/commits/operations'
|
||||
import {
|
||||
ResourceIdentifier,
|
||||
ResourceIdentifierInput,
|
||||
@@ -21,8 +22,7 @@ import {
|
||||
import { CommitRecord } from '@/modules/core/helpers/types'
|
||||
import {
|
||||
getAllBranchCommits,
|
||||
getCommitsAndTheirBranchIds,
|
||||
getSpecificBranchCommits
|
||||
getCommitsAndTheirBranchIds
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getStreamObjects } from '@/modules/core/repositories/objects'
|
||||
import { Optional, SpeckleViewer } from '@speckle/shared'
|
||||
@@ -159,7 +159,7 @@ const getVersionResourceGroupsIncludingAllVersionsFactory =
|
||||
|
||||
type GetVersionResourceGroupsLoadedVersionsOnlyDeps = {
|
||||
getStreamBranchesByName: GetStreamBranchesByName
|
||||
getSpecificBranchCommits: typeof getSpecificBranchCommits
|
||||
getSpecificBranchCommits: GetSpecificBranchCommits
|
||||
getBranchLatestCommits: GetBranchLatestCommits
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
} from '@/modules/core/repositories/branches'
|
||||
import {
|
||||
getAllBranchCommits,
|
||||
getSpecificBranchCommits
|
||||
getSpecificBranchCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { getObject, getStreamObjects } from '@/modules/core/repositories/objects'
|
||||
import {
|
||||
@@ -67,7 +67,7 @@ const crossServerSyncModule: SpeckleModule = {
|
||||
getStreamObjects,
|
||||
getBranchLatestCommits: getBranchLatestCommitsFactory({ db }),
|
||||
getStreamBranchesByName: getStreamBranchesByNameFactory({ db }),
|
||||
getSpecificBranchCommits,
|
||||
getSpecificBranchCommits: getSpecificBranchCommitsFactory({ db }),
|
||||
getAllBranchCommits
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user