Skip to content

Commit

Permalink
🔨 improve tag graph types
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Jan 7, 2025
1 parent 7f08a9a commit 200ca89
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,18 +544,23 @@ export async function getFlatTagGraph(knex: KnexReadonlyTransaction): Promise<
// Use this with getUniqueNamesFromParentTagArrays to get Record<string, string[]> instead
export async function getParentTagArraysByChildName(
trx: KnexReadonlyTransaction
): Promise<Record<DbPlainTag["name"], DbPlainTag[][]>> {
): Promise<
Record<DbPlainTag["name"], Pick<DbPlainTag, "id" | "name" | "slug">[][]>
> {
const { __rootId, ...flatTagGraph } = await getFlatTagGraph(trx)
const tagGraph = createTagGraph(flatTagGraph, __rootId)
const tagsById = await trx("tags")
const tagsById = await trx<DbPlainTag>("tags")
.select("id", "name", "slug")
.then((tags) => keyBy(tags, "id"))

const pathsByChildName: Record<DbPlainTag["name"], DbPlainTag[][]> = {}
const pathsByChildName: Record<
DbPlainTag["name"],
Pick<DbPlainTag, "id" | "name" | "slug">[][]
> = {}

function trackAllPaths(
node: TagGraphNode,
currentPath: DbPlainTag[] = []
currentPath: Pick<DbPlainTag, "id" | "name" | "slug">[] = []
): void {
const currentTag = tagsById[node.id]
const newPath = [...currentPath, currentTag]
Expand Down

0 comments on commit 200ca89

Please sign in to comment.