Skip to content

Commit

Permalink
Use subquery to groups artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed May 1, 2024
1 parent 8b7a22c commit 3e02120
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions components/Releases.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<Button @click="upload" label="Upload" class="mb-3"></Button>
<div class="card p-0">
<DataTable :value="list" single @row-click="selectRow($event)" selectionMode="single">
<Column field="releaseId" header="Release Id" style="width: 15%"></Column>
<Column field="versionName2" header="Version Name"></Column>
<Column field="versionCode2" header="Version Code"></Column>
<Column field="groups" header="Groups">
<Column field="artifacts.releaseId" header="Release Id" style="width: 15%"></Column>
<Column field="artifacts.versionName2" header="Version Name"></Column>
<Column field="artifacts.versionCode2" header="Version Code"></Column>
<Column header="Groups">
<template #body="slotProps">
<label>
{{ formatGroups(slotProps.data.groups) }}
{{ slotProps.data.groups.names }}
</label>
</template>
</Column>
Expand Down Expand Up @@ -69,6 +69,6 @@ const upload = () => {
const selectRow = async (row: DataTableRowClickEvent) => {
console.log(row.data)
await navigateTo(`/orgs/${props.orgName}/apps/${props.appName}/${row.data.releaseId}`)
await navigateTo(`/orgs/${props.orgName}/apps/${props.appName}/${row.data.artifacts.releaseId}`)
}
</script>
1 change: 1 addition & 0 deletions server/api/artifacts/detail-artifact.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default defineEventHandler(async (event) => {
return operators.and(operators.eq(fields.organizationsId, userOrg.organizationsId!), operators.eq(fields.name, appName!.toString()))
},
}).then(takeUniqueOrThrow)
console.log('ffffff', releaseId)
const releaseIdInt = parseInt(releaseId!.toString())
const detailArtifact = await db.query.artifacts.findMany({
where(fields, operators) {
Expand Down
37 changes: 20 additions & 17 deletions server/api/artifacts/list-artifacts.get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { and, eq } from "drizzle-orm"
import { and, desc, eq, sql } from "drizzle-orm"
import { artifacts, artifactsGroups, artifactsGroupsManager, organizations, organizationsPeople } from "~/server/db/schema"
import { getStorageKeys } from "~/server/utils/utils"
import { takeUniqueOrThrow } from "../detail-app.get"
import { concat } from "drizzle-orm/sqlite-core/expressions"

export default defineEventHandler(async (event) => {
const db = event.context.drizzle
Expand All @@ -19,23 +20,25 @@ export default defineEventHandler(async (event) => {
return operators.and(operators.eq(fields.organizationsId, userOrg.organizationsId!), operators.eq(fields.name, appName!.toString()))
},
}).then(takeUniqueOrThrow)
const artficats = await db.query.artifacts.findMany({
where(fields, operators) {
return operators.eq(fields.appsId, app.id)
},
orderBy(fields, operators) {
return operators.desc(fields.releaseId)
},
const groupsQuery = db.select({
artifactId: artifacts.id,
names: sql`group_concat(${artifactsGroups.name}, ', ')`.as('names'),
})
const artifactGroups = await Promise.all(artficats.map(async e => {
const groups = await db.select()
.from(artifactsGroups)
.leftJoin(artifactsGroupsManager, eq(artifactsGroupsManager.artifactsGroupsId, artifactsGroups.id))
.where(eq(artifactsGroupsManager.artifactsId, e.id))
return {
...e,
groups,
.from(artifacts)
.leftJoin(artifactsGroupsManager, and(eq(artifactsGroupsManager.artifactsId, artifacts.id)))
.leftJoin(artifactsGroups, and(eq(artifactsGroups.id, artifactsGroupsManager.artifactsGroupsId)))
.groupBy(artifacts.id)
.as('groups')
const artifactGroups = await db.select()
.from(artifacts)
.leftJoin(groupsQuery, eq(groupsQuery.artifactId, artifacts.id))
.where(eq(artifacts.appsId, app.id))
.orderBy(desc(artifacts.releaseId))
artifactGroups.forEach(v => {
v.artifacts.fileObjectKey = ''
if (v.groups) {
v.groups.artifactId = ''
}
}))
})
return artifactGroups
})
4 changes: 0 additions & 4 deletions utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,3 @@ export function formatBytes(bytes: number, decimals = 2, isBinary = false) {
export const formatDate = (value?: string | null) => {
return moment(value).format('LLL')
}

export const formatGroups = (groups: any[] | undefined) => {
return groups && groups.length ? _.join(groups.map(e => e.artifactsGroups.name), ', ') : '-'
}

0 comments on commit 3e02120

Please sign in to comment.