mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Try using memoized list mothods
This commit is contained in:
parent
fb6eff5b95
commit
ed17e2f29a
1 changed files with 41 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ 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 { PromisePool } from '@supercharge/promise-pool'
|
||||||
|
import memoize from 'fast-memoize'
|
||||||
|
|
||||||
import buildAppList from '~/helpers/build-app-list.js'
|
import buildAppList from '~/helpers/build-app-list.js'
|
||||||
import buildGamesList from '~/helpers/build-game-list.js'
|
import buildGamesList from '~/helpers/build-game-list.js'
|
||||||
|
|
@ -42,6 +43,9 @@ import {
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
|
|
||||||
|
let timeRunGetListArray = 0
|
||||||
|
let timeRunGetListByCategories = 0
|
||||||
|
|
||||||
|
|
||||||
function normalizeVersion ( rawVersion ) {
|
function normalizeVersion ( rawVersion ) {
|
||||||
const containsNumbers = /\d+/.test( rawVersion )
|
const containsNumbers = /\d+/.test( rawVersion )
|
||||||
|
|
@ -280,18 +284,53 @@ class BuildLists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getListArray ( listName ) {
|
||||||
|
console.log(`getListArray run ${ timeRunGetListArray += 1 } times`)
|
||||||
|
|
||||||
|
return Array.from( this.lists[ listName ] )
|
||||||
|
}
|
||||||
|
|
||||||
|
getListArrayMemoized = memoize( this.getListArray.bind( this ) )
|
||||||
|
|
||||||
|
getListByCategories ( listName ) {
|
||||||
|
console.log(`getListByCategories run ${ timeRunGetListByCategories += 1 } times`)
|
||||||
|
|
||||||
|
const list = this.getListArrayMemoized( listName )
|
||||||
|
|
||||||
|
return list.reduce( ( categories, app ) => {
|
||||||
|
|
||||||
|
const category = app.category
|
||||||
|
|
||||||
|
if ( !categories[category] ) {
|
||||||
|
categories[category] = []
|
||||||
|
}
|
||||||
|
|
||||||
|
categories[category].push( app )
|
||||||
|
|
||||||
|
return categories
|
||||||
|
}, {} )
|
||||||
|
}
|
||||||
|
|
||||||
|
getListByCategoriesMemoized = memoize( this.getListByCategories.bind( this ) )
|
||||||
|
|
||||||
|
getCategoryList ( category, listName = 'app' ) {
|
||||||
|
const list = this.getListByCategoriesMemoized( listName )
|
||||||
|
|
||||||
|
return list[category] || []
|
||||||
|
}
|
||||||
|
|
||||||
makeKindLists () {
|
makeKindLists () {
|
||||||
const getters = Object.fromEntries( Object.entries( this.lists ).map( ([ listName ]) => {
|
const getters = Object.fromEntries( Object.entries( this.lists ).map( ([ listName ]) => {
|
||||||
return [
|
return [
|
||||||
// Key
|
// Key
|
||||||
listName,
|
listName,
|
||||||
() => Array.from( this.lists[ listName ] )
|
() => this.getListArrayMemoized( listName )
|
||||||
]
|
]
|
||||||
} ) )
|
} ) )
|
||||||
|
|
||||||
// Add getters for categories
|
// Add getters for categories
|
||||||
for ( const categorySlug in categories ) {
|
for ( const categorySlug in categories ) {
|
||||||
getters[categorySlug] = () => Array.from( this.lists.app ).filter( app => app.category.slug === categorySlug )
|
getters[categorySlug] = () => this.getCategoryList( categorySlug )
|
||||||
}
|
}
|
||||||
|
|
||||||
const kindLists = {}
|
const kindLists = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue