Skip to content

Commit

Permalink
Memoize determining git release commit (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobofan authored Oct 27, 2023
1 parent 9cfd57c commit f0890f7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions data/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { promises as fs } from 'fs'
import { gitlogPromise } from 'gitlog'
import * as os from 'os'
import pMemoize from 'p-memoize'
import allModules from '../pages/all-modules'

export const MODULES_ROOT_DIR = path.join(
process.cwd(),
Expand Down Expand Up @@ -39,14 +38,18 @@ export const listModuleVersions = async (module: string): Promise<string[]> => {
return metadata.versions
}

export const getModuleMetadata = async (module: string): Promise<Metadata> => {
export const getModuleMetadataInner = async (
module: string
): Promise<Metadata> => {
const metadataJsonPath = path.join(MODULES_ROOT_DIR, module, 'metadata.json')
const metadataContents = await fs.readFile(metadataJsonPath)
const metadata: Metadata = JSON.parse(metadataContents.toString())

return metadata
}

export const getModuleMetadata = pMemoize(getModuleMetadataInner)

export interface SearchIndexEntry {
module: string
version: string
Expand Down Expand Up @@ -81,7 +84,7 @@ export interface Commit {
authorDateRel: string
}

export const getSubmissionCommitOfVersion = async (
const getSubmissionCommitOfVersionInternal = async (
module: string,
version: string
): Promise<Commit> => {
Expand All @@ -104,6 +107,10 @@ export const getSubmissionCommitOfVersion = async (
}
}

export const getSubmissionCommitOfVersion = pMemoize(
getSubmissionCommitOfVersionInternal
)

// TODO: find a more robust way to do this
export const getCompatibilityLevelOfVersion = async (
module: string,
Expand Down

0 comments on commit f0890f7

Please sign in to comment.