mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Use for loop instead of promise pool
This commit is contained in:
parent
01a5d15147
commit
b6b4967208
1 changed files with 47 additions and 52 deletions
|
|
@ -3,7 +3,6 @@ import { dirname, basename } from 'path'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
import semver from 'semver'
|
import semver from 'semver'
|
||||||
import { PromisePool } from '@supercharge/promise-pool'
|
|
||||||
import memoize from 'fast-memoize'
|
import memoize from 'fast-memoize'
|
||||||
import has from 'just-has'
|
import has from 'just-has'
|
||||||
|
|
||||||
|
|
@ -241,6 +240,7 @@ class BuildLists {
|
||||||
|
|
||||||
// Sort versions by semver
|
// Sort versions by semver
|
||||||
const versions = Object.entries( versionsObject ).sort( ( [ aVersionRaw ], [ bVersionRaw ] ) => {
|
const versions = Object.entries( versionsObject ).sort( ( [ aVersionRaw ], [ bVersionRaw ] ) => {
|
||||||
|
// console.log( 'a, b', aVersionRaw, bVersionRaw )
|
||||||
const aVersion = normalizeVersion( aVersionRaw )
|
const aVersion = normalizeVersion( aVersionRaw )
|
||||||
const bVersion = normalizeVersion( bVersionRaw )
|
const bVersion = normalizeVersion( bVersionRaw )
|
||||||
|
|
||||||
|
|
@ -450,76 +450,71 @@ class BuildLists {
|
||||||
|
|
||||||
const apiListDirectory = `${ apiDirectory }/${ listOptions.endpointPrefix }`
|
const apiListDirectory = `${ apiDirectory }/${ listOptions.endpointPrefix }`
|
||||||
|
|
||||||
const poolSize = 1000
|
// const poolSize = 1000
|
||||||
|
|
||||||
// Store app bundles to memory
|
// Store app bundles to memory
|
||||||
await this.getSavedAppBundles({
|
await this.getSavedAppBundles({
|
||||||
keepBundlesInMemory: true
|
keepBundlesInMemory: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const { errors } = await PromisePool
|
// await Promise.all( this.getListArrayMemoized( listOptions.name ).map( async ( listEntry ) => {
|
||||||
.withConcurrency( poolSize )
|
for ( const listEntry of this.getListArrayMemoized( listOptions.name ) ) {
|
||||||
.for( this.getListArrayMemoized( listOptions.name ) )
|
|
||||||
.process(async ( listEntry, index, pool ) => {
|
|
||||||
// console.log('listEntry', listEntry)
|
|
||||||
|
|
||||||
const {
|
// console.log('listEntry', listEntry)
|
||||||
// name,
|
|
||||||
// aliases,
|
|
||||||
// status,
|
|
||||||
// bundleIds,
|
|
||||||
endpoint,
|
|
||||||
|
|
||||||
} = listEntry
|
const {
|
||||||
|
// name,
|
||||||
|
// aliases,
|
||||||
|
// status,
|
||||||
|
// bundleIds,
|
||||||
|
endpoint,
|
||||||
|
|
||||||
const endpointPath = `${ apiDirectory }${ endpoint }.json`
|
} = listEntry
|
||||||
const endpointDirectory = dirname(endpointPath)
|
|
||||||
|
|
||||||
// Add related videos
|
const endpointPath = `${ apiDirectory }${ endpoint }.json`
|
||||||
if ( this.shouldHaveRelatedVideos( listEntry ) ) {
|
const endpointDirectory = dirname(endpointPath)
|
||||||
listEntry.relatedVideos = getRelatedVideos({
|
|
||||||
listing: listEntry,
|
|
||||||
videoListSet: this.lists.video,
|
|
||||||
appListSet: this.allVideoAppsList
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add App Bundles
|
// Add related videos
|
||||||
if ( Array.isArray( listEntry.bundleIds ) ) {
|
if ( this.shouldHaveRelatedVideos( listEntry ) ) {
|
||||||
listEntry.bundles = await this.getAppBundles( listEntry )
|
listEntry.relatedVideos = getRelatedVideos({
|
||||||
|
listing: listEntry,
|
||||||
|
videoListSet: this.lists.video,
|
||||||
|
appListSet: this.allVideoAppsList
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
listEntry.bundles = this.sortBundleVersions( listEntry.bundles )
|
// Add App Bundles
|
||||||
}
|
if ( Array.isArray( listEntry.bundleIds ) ) {
|
||||||
|
listEntry.bundles = await this.getAppBundles( listEntry )
|
||||||
|
|
||||||
|
listEntry.bundles = this.sortBundleVersions( listEntry.bundles )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add device support
|
// Add device support
|
||||||
if ( this.shouldHaveDeviceSupport( listEntry ) ) {
|
if ( this.shouldHaveDeviceSupport( listEntry ) ) {
|
||||||
const deviceList = this.getListArrayMemoized( 'device' )
|
const deviceList = this.getListArrayMemoized( 'device' )
|
||||||
|
|
||||||
listEntry.deviceSupport = deviceList.map( device => {
|
listEntry.deviceSupport = deviceList.map( device => {
|
||||||
const supportsApp = deviceSupportsApp( device, listEntry )
|
const supportsApp = deviceSupportsApp( device, listEntry )
|
||||||
return {
|
return {
|
||||||
...device,
|
...device,
|
||||||
emoji: supportsApp ? '✅' : '🚫',
|
emoji: supportsApp ? '✅' : '🚫',
|
||||||
ariaLabel: `${ listEntry.name } has ${ supportsApp ? '' : 'not' } been reported to work on ${ device.name }`
|
ariaLabel: `${ listEntry.name } has ${ supportsApp ? '' : 'not' } been reported to work on ${ device.name }`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasSaveMethod = has( listOptions, 'beforeSave' )
|
const hasSaveMethod = has( listOptions, 'beforeSave' )
|
||||||
const saveMethod = hasSaveMethod ? listOptions.beforeSave : listSet => Array.from( listSet )
|
const saveMethod = hasSaveMethod ? listOptions.beforeSave : listSet => Array.from( listSet )
|
||||||
|
|
||||||
const [ saveableEntry ] = saveMethod( new Set( [ listEntry ] ) )
|
const [ saveableEntry ] = saveMethod( new Set( [ listEntry ] ) )
|
||||||
|
|
||||||
// Ensure the directory exists
|
// Ensure the directory exists
|
||||||
await fs.ensureDir( endpointDirectory )
|
await fs.ensureDir( endpointDirectory )
|
||||||
|
|
||||||
// Write the endpoint to JSON
|
// Write the endpoint to JSON
|
||||||
await this.saveToJson( saveableEntry, endpointPath )
|
await this.saveToJson( saveableEntry, endpointPath )
|
||||||
})
|
|
||||||
|
|
||||||
if ( errors.length !== 0 ) {
|
|
||||||
throw new Error( errors )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count saved files
|
// Count saved files
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue