mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Store lists as Sets
This commit is contained in:
parent
c7d39dd9f2
commit
1f5f47eab4
10 changed files with 30 additions and 38 deletions
|
|
@ -55,7 +55,10 @@ class BuildLists {
|
|||
path: '/static/video-list.json',
|
||||
buildMethod: async () => {
|
||||
|
||||
// const videoList = await buildVideoList( buildArgs )
|
||||
return await buildVideoList( this.getAllVideoAppsList() )
|
||||
|
||||
|
||||
// const videoList = await buildVideoList( this.getAllVideoAppsList() )
|
||||
|
||||
// const extraVideos = []
|
||||
|
||||
|
|
@ -70,14 +73,10 @@ class BuildLists {
|
|||
// })
|
||||
// }
|
||||
|
||||
// return [
|
||||
// return new Set([
|
||||
// ...videoList,
|
||||
// ...extraVideos
|
||||
// ].slice(0, 10 * 1000)
|
||||
|
||||
// return await this.saveList(videoListOptions, allVideoAppsList)
|
||||
|
||||
return await buildVideoList( this.getAllVideoAppsList() )
|
||||
// ].slice(0, 10 * 1000))
|
||||
},
|
||||
}
|
||||
]
|
||||
|
|
@ -112,7 +111,7 @@ class BuildLists {
|
|||
// console.log('listFullPath', listFullPath)
|
||||
|
||||
// Write the list to JSON
|
||||
await fs.writeFile(listFullPath, JSON.stringify(this.lists[listOptions.name]))
|
||||
await fs.writeFile(listFullPath, JSON.stringify(Array.from(this.lists[listOptions.name])))
|
||||
|
||||
// Read back the JSON we just wrote to ensure it exists
|
||||
const savedListJSON = await fs.readFile(listFullPath, 'utf-8')
|
||||
|
|
@ -134,8 +133,12 @@ class BuildLists {
|
|||
const methodName = `Building ${listOptions.path}`
|
||||
console.time(methodName)
|
||||
|
||||
const builtList = await listOptions.buildMethod()
|
||||
|
||||
// Run the build method to get the lists
|
||||
this.lists[listOptions.name] = await listOptions.buildMethod()
|
||||
this.lists[listOptions.name] = new Set([
|
||||
...builtList
|
||||
])
|
||||
|
||||
|
||||
console.timeEnd(methodName)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { appsRelatedToVideo, videosRelatedToVideo, videosRelatedToApp } from './
|
|||
// import videoList from '~/static/video-list.json'
|
||||
|
||||
|
||||
export function buildVideoPayload ( video, allVideoAppsList, videoList ) {
|
||||
export function buildVideoPayload ( video, allVideoAppsList, videoListSet ) {
|
||||
// const { appsRelatedToVideo, videosRelatedToVideo } = await import('~/helpers/related.js')
|
||||
// const { default: videoList } = await import('~/static/video-list.json')
|
||||
|
||||
|
|
@ -15,18 +15,18 @@ export function buildVideoPayload ( video, allVideoAppsList, videoList ) {
|
|||
const featuredApps = appsRelatedToVideo( video, allVideoAppsList )
|
||||
|
||||
// Get related videos
|
||||
const relatedVideos = videosRelatedToVideo( video, allVideoAppsList, videoList )
|
||||
const relatedVideos = videosRelatedToVideo( video, allVideoAppsList, videoListSet )
|
||||
|
||||
return {
|
||||
video,
|
||||
featuredApps,
|
||||
// If no related video found just get the 12 newest ones
|
||||
relatedVideos: (relatedVideos.length !== 0) ? relatedVideos.slice(0, 24) : videoList.slice(0, 12)
|
||||
relatedVideos: (relatedVideos.length !== 0) ? relatedVideos.slice(0, 24) : Array.from(videoListSet).slice(0, 12)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function buildAppBenchmarkPayload ( app, allVideoAppsList, videoList ) {
|
||||
export function buildAppBenchmarkPayload ( app, allVideoAppsList, videoListSet ) {
|
||||
// const { allVideoAppsList } = await import('~/helpers/get-list.js')
|
||||
|
||||
// const { videosRelatedToApp } = await import('~/helpers/related.js')
|
||||
|
|
@ -39,7 +39,7 @@ export function buildAppBenchmarkPayload ( app, allVideoAppsList, videoList ) {
|
|||
|
||||
// const featuredApps = []
|
||||
|
||||
const relatedVideos = videosRelatedToApp( app, videoList ).map(video => {
|
||||
const relatedVideos = videosRelatedToApp( app, videoListSet ).map(video => {
|
||||
// console.log('video', video)
|
||||
return {
|
||||
...video,
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ export const allList = [
|
|||
]
|
||||
|
||||
|
||||
export function makeAppSearchLinks ( app, videoList ) {
|
||||
export function makeAppSearchLinks ( app, videoListSet ) {
|
||||
|
||||
const videos = videosRelatedToApp( app, videoList )
|
||||
const videos = videosRelatedToApp( app, videoListSet )
|
||||
|
||||
// If there are no videos
|
||||
// then skip
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export function appsRelatedToVideo ( video, allVideoAppsList ) {
|
|||
return relatedApps
|
||||
}
|
||||
|
||||
export function videosRelatedToVideo ( video, allVideoAppsList, videoList ) {
|
||||
export function videosRelatedToVideo ( video, allVideoAppsList, videoListSet ) {
|
||||
const relatedVideos = {}
|
||||
|
||||
// console.log('videoList', videoList[0])
|
||||
|
|
@ -30,7 +30,7 @@ export function videosRelatedToVideo ( video, allVideoAppsList, videoList ) {
|
|||
const featuredApps = appsRelatedToVideo( video, allVideoAppsList )
|
||||
|
||||
// Find other videos that also feature this video's app
|
||||
for (const otherVideo of videoList) {
|
||||
for (const otherVideo of videoListSet) {
|
||||
for (const app of featuredApps) {
|
||||
// console.log('otherVideo', otherVideo)
|
||||
// Skip if this app is not in the other video's apps
|
||||
|
|
@ -48,12 +48,14 @@ export function videosRelatedToVideo ( video, allVideoAppsList, videoList ) {
|
|||
}
|
||||
|
||||
|
||||
export function videosRelatedToApp ( app, videoList ) {
|
||||
export function videosRelatedToApp ( app, videoListSet ) {
|
||||
|
||||
// console.log('videoListSet', videoListSet)
|
||||
|
||||
const relatedVideos = {}
|
||||
|
||||
// Find other videos that also feature this video's app
|
||||
for (const video of videoList) {
|
||||
for (const video of videoListSet) {
|
||||
if (!video.apps.includes(app.slug)) continue
|
||||
|
||||
relatedVideos[video.id] = video
|
||||
|
|
|
|||
|
|
@ -1,19 +1,6 @@
|
|||
import { promises as fs } from 'fs'
|
||||
// import path from 'path'
|
||||
|
||||
import pkg from './package'
|
||||
import buildAppList from './helpers/build-app-list.js'
|
||||
import buildGamesList from './helpers/build-game-list.js'
|
||||
import buildHomebrewList from './helpers/build-homebrew-list.js'
|
||||
import buildVideoList from './helpers/build-video-list.js'
|
||||
|
||||
import { buildVideoPayload, buildAppBenchmarkPayload } from './helpers/build-payload.js'
|
||||
|
||||
import { categories } from './helpers/categories.js'
|
||||
import { getAppEndpoint, getVideoEndpoint } from './helpers/app-derived.js'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export default {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export default {
|
|||
|
||||
const app = appList.find(app => (app.slug === slug))
|
||||
|
||||
const relatedVideos = videosRelatedToApp( app, videoList )
|
||||
const relatedVideos = videosRelatedToApp( app, (new Set(videoList)) )
|
||||
|
||||
// Find other videos that also feature this video's app
|
||||
// for (const video of videoList) {
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ export default {
|
|||
|
||||
const app = gameList.find(app => (app.slug === slug))
|
||||
|
||||
const relatedVideos = videosRelatedToApp( app, videoList )
|
||||
const relatedVideos = videosRelatedToApp( app, (new Set(videoList)) )
|
||||
|
||||
// Find other videos that also feature this video's app
|
||||
// for (const video of videoList) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export default {
|
|||
text: app.text,
|
||||
lastUpdated: app.lastUpdated,
|
||||
category: app.category,
|
||||
searchLinks: makeAppSearchLinks( app, videoList )
|
||||
searchLinks: makeAppSearchLinks( app, (new Set(videoList)) )
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ export default {
|
|||
|
||||
allVideoAppsList.forEach( app => {
|
||||
// Make the search links
|
||||
const searchLinks = makeAppSearchLinks( app, videoList )
|
||||
const searchLinks = makeAppSearchLinks( app, (new Set(videoList)) )
|
||||
|
||||
// If there are more than zero
|
||||
// add them to our list
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ export default {
|
|||
text: app.text,
|
||||
lastUpdated: app.lastUpdated,
|
||||
category: app.category,
|
||||
searchLinks: makeAppSearchLinks( app, videoList )
|
||||
searchLinks: makeAppSearchLinks( app, (new Set(videoList)) )
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue