Merge pull request #3174 from specklesystems/fabians/core-ioc-21

chore(server): core IoC 21 - getCommitsAndTheirBranchIdsFactory
This commit is contained in:
Alessandro Magionami
2024-10-07 16:24:02 +02:00
committed by GitHub
5 changed files with 27 additions and 19 deletions
@@ -17,7 +17,7 @@ import {
} from '@/modules/core/repositories/branches'
import {
getAllBranchCommitsFactory,
getCommitsAndTheirBranchIds,
getCommitsAndTheirBranchIdsFactory,
getSpecificBranchCommitsFactory
} from '@/modules/core/repositories/commits'
import { getStreamObjects } from '@/modules/core/repositories/objects'
@@ -60,7 +60,7 @@ export async function addCommentCreatedActivity(params: {
getViewerResourcesFromLegacyIdentifiers: (...args) =>
getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep
}),
getCommitsAndTheirBranchIds,
getCommitsAndTheirBranchIds: getCommitsAndTheirBranchIdsFactory({ db }),
getStreamObjects
})
const getViewerResourceItemsUngrouped = getViewerResourceItemsUngroupedFactory({
@@ -146,7 +146,7 @@ export async function addCommentArchivedActivity(params: {
getViewerResourcesFromLegacyIdentifiers: (...args) =>
getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep
}),
getCommitsAndTheirBranchIds,
getCommitsAndTheirBranchIds: getCommitsAndTheirBranchIdsFactory({ db }),
getStreamObjects
})
@@ -208,7 +208,7 @@ export async function addReplyAddedActivity(params: {
getViewerResourcesFromLegacyIdentifiers: (...args) =>
getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep
}),
getCommitsAndTheirBranchIds,
getCommitsAndTheirBranchIds: getCommitsAndTheirBranchIdsFactory({ db }),
getStreamObjects
})
@@ -87,7 +87,7 @@ import { getBlobsFactory } from '@/modules/blobstorage/repositories'
import { ResourceIdentifier } from '@/modules/comments/domain/types'
import {
getAllBranchCommitsFactory,
getCommitsAndTheirBranchIds,
getCommitsAndTheirBranchIdsFactory,
getSpecificBranchCommitsFactory
} from '@/modules/core/repositories/commits'
import { getStreamObjects } from '@/modules/core/repositories/objects'
@@ -148,7 +148,7 @@ const getViewerResourcesFromLegacyIdentifiers =
getViewerResourcesFromLegacyIdentifiers: (...args) =>
getViewerResourcesFromLegacyIdentifiers(...args) // recursive dep
}),
getCommitsAndTheirBranchIds,
getCommitsAndTheirBranchIds: getCommitsAndTheirBranchIdsFactory({ db }),
getStreamObjects
})
@@ -149,3 +149,7 @@ export type GetUserAuthoredCommitCounts = (params: {
}) => Promise<{
[userId: string]: number
}>
export type GetCommitsAndTheirBranchIds = (
commitIds: string[]
) => Promise<BranchCommit[]>
@@ -40,7 +40,8 @@ import {
GetStreamCommitCounts,
GetStreamCommitCount,
GetUserStreamCommitCounts,
GetUserAuthoredCommitCounts
GetUserAuthoredCommitCounts,
GetCommitsAndTheirBranchIds
} from '@/modules/core/domain/commits/operations'
const tables = {
@@ -222,17 +223,20 @@ export const getStreamCommitCountFactory =
return res?.count || 0
}
export async function getCommitsAndTheirBranchIds(commitIds: string[]) {
if (!commitIds.length) return []
export const getCommitsAndTheirBranchIdsFactory =
(deps: { db: Knex }): GetCommitsAndTheirBranchIds =>
async (commitIds: string[]) => {
if (!commitIds.length) return []
return await 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)
}
return await 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)
}
export const getSpecificBranchCommitsFactory =
(deps: { db: Knex }): GetSpecificBranchCommits =>
@@ -12,6 +12,7 @@ import {
} from '@/modules/core/domain/branches/operations'
import {
GetAllBranchCommits,
GetCommitsAndTheirBranchIds,
GetSpecificBranchCommits
} from '@/modules/core/domain/commits/operations'
import {
@@ -23,7 +24,6 @@ import {
ViewerUpdateTrackingTarget
} from '@/modules/core/graph/generated/graphql'
import { CommitRecord } from '@/modules/core/helpers/types'
import { getCommitsAndTheirBranchIds } from '@/modules/core/repositories/commits'
import { getStreamObjects } from '@/modules/core/repositories/objects'
import { Optional, SpeckleViewer } from '@speckle/shared'
import { flatten, keyBy, reduce, uniq, uniqWith } from 'lodash'
@@ -370,7 +370,7 @@ export const getViewerResourcesFromLegacyIdentifiersFactory =
(
deps: {
getViewerResourcesForComments: GetViewerResourcesForComments
getCommitsAndTheirBranchIds: typeof getCommitsAndTheirBranchIds
getCommitsAndTheirBranchIds: GetCommitsAndTheirBranchIds
} & GetObjectResourceGroupsDeps
): GetViewerResourcesFromLegacyIdentifiers =>
async (