From 1f5f47eab4c69ef07546fdbeb5c7b2548c657c22 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Fri, 22 Jan 2021 23:14:44 -0600 Subject: [PATCH] Store lists as Sets --- build-lists.js | 21 ++++++++++++--------- helpers/build-payload.js | 10 +++++----- helpers/get-list.js | 4 ++-- helpers/related.js | 10 ++++++---- nuxt.config.js | 13 ------------- pages/app/_slug/index.vue | 2 +- pages/game/_slug/index.vue | 2 +- pages/games.vue | 2 +- pages/index.vue | 2 +- pages/kind/_slug.vue | 2 +- 10 files changed, 30 insertions(+), 38 deletions(-) diff --git a/build-lists.js b/build-lists.js index 8e166e6..a8f1332 100644 --- a/build-lists.js +++ b/build-lists.js @@ -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) diff --git a/helpers/build-payload.js b/helpers/build-payload.js index c822552..0d3e65c 100644 --- a/helpers/build-payload.js +++ b/helpers/build-payload.js @@ -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, diff --git a/helpers/get-list.js b/helpers/get-list.js index ac861c4..2129d73 100644 --- a/helpers/get-list.js +++ b/helpers/get-list.js @@ -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 diff --git a/helpers/related.js b/helpers/related.js index 700b289..a8a65fc 100644 --- a/helpers/related.js +++ b/helpers/related.js @@ -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 diff --git a/nuxt.config.js b/nuxt.config.js index 0f8657e..f7f0553 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -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 { diff --git a/pages/app/_slug/index.vue b/pages/app/_slug/index.vue index 80f1e1c..55effc8 100644 --- a/pages/app/_slug/index.vue +++ b/pages/app/_slug/index.vue @@ -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) { diff --git a/pages/game/_slug/index.vue b/pages/game/_slug/index.vue index 625f6a7..5cf5d5a 100644 --- a/pages/game/_slug/index.vue +++ b/pages/game/_slug/index.vue @@ -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) { diff --git a/pages/games.vue b/pages/games.vue index fdc7981..b43ec61 100644 --- a/pages/games.vue +++ b/pages/games.vue @@ -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)) ) } }) } diff --git a/pages/index.vue b/pages/index.vue index bb58b63..cde2988 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -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 diff --git a/pages/kind/_slug.vue b/pages/kind/_slug.vue index 92603a7..32c61c2 100644 --- a/pages/kind/_slug.vue +++ b/pages/kind/_slug.vue @@ -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)) ) } }) }