Skip to content

Commit

Permalink
fix(api): πŸ› games are not duplicated for a given release or tag (#492)
Browse files Browse the repository at this point in the history
Include local dev data.

βœ… Closes: #491
  • Loading branch information
andrew-codes authored Aug 16, 2024
2 parents e126f7d + c76ab18 commit ba6e63c
Show file tree
Hide file tree
Showing 31 changed files with 87 additions and 64 deletions.
Binary file modified .data/games/agerating.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/agerating.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"4910f19cfe5e497cba8135106061fbf2","collectionName":"agerating","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"36e900b16aa94018bf9c744eab3fe290","collectionName":"agerating","type":"collection"}
Binary file modified .data/games/assets.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/assets.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"49864dfc319b4456880df0075f64a6f7","collectionName":"assets","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"8a19cf814cc34ac4928df8f9f9b53b94","collectionName":"assets","type":"collection"}
Binary file modified .data/games/company.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/company.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"cd8542959d9b41ccae0a197fad38585d","collectionName":"company","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"4a6e5e537167467e958726f77af9339f","collectionName":"company","type":"collection"}
Binary file modified .data/games/completionstatus.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/completionstatus.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"25e892ab0e204d7099b87c6f7b3fa3be","collectionName":"completionstatus","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"1e0c3290b51e4988bf5e40d63cd04d8e","collectionName":"completionstatus","type":"collection"}
Binary file modified .data/games/consolidated-games.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/consolidated-games.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"eeba5ef3253046debdf955836b0e23e5","collectionName":"consolidated-games","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"c813d5dccc764cdd9f53fc92cd885228","collectionName":"consolidated-games","type":"collection"}
Binary file modified .data/games/game.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/game.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"6afdb1473dae413da5cbc3fa0298d90b","collectionName":"game","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"14e3e4eb1ff5466eb6a65c7517e2ac58","collectionName":"game","type":"collection"}
Binary file modified .data/games/gamefeature.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/gamefeature.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"422377182dcf4de49ace4ed224015e24","collectionName":"gamefeature","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"9ef6bf04d2684510a3519cd240fe18a0","collectionName":"gamefeature","type":"collection"}
Binary file modified .data/games/gamesource.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/gamesource.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"c9efdc97c44a432f9f5bdd5718aae120","collectionName":"gamesource","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"170e9232130e4c2fbc08e1c495d31136","collectionName":"gamesource","type":"collection"}
Binary file modified .data/games/genre.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/genre.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"ca53ece8f111420b89e6bd582b45a916","collectionName":"genre","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"0ea04227a82b40efaab7be21ddabc4c1","collectionName":"genre","type":"collection"}
Binary file modified .data/games/platform.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/platform.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"0ed6d6cbbd934a5f95aa41427812beb8","collectionName":"platform","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"b0699a5c85a9408c978d7bf58d60dfd5","collectionName":"platform","type":"collection"}
Binary file modified .data/games/region.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/region.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"67920823e8914dfaab3f06efc74bae2a","collectionName":"region","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"7d7c69f8238f4a42ae76e18b744d3f08","collectionName":"region","type":"collection"}
Binary file modified .data/games/series.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/series.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"e0d726cb9c5549849c279cba90d33143","collectionName":"series","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"2d7c4ceb0cc84e9983d0a7578cd0fbec","collectionName":"series","type":"collection"}
Binary file modified .data/games/tag.bson
Binary file not shown.
2 changes: 1 addition & 1 deletion .data/games/tag.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"7e824dacb8874e308b24b6fb7022119c","collectionName":"tag","type":"collection"}
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"}],"uuid":"5b24eaae57914aa880ba55721dd20f2e","collectionName":"tag","type":"collection"}
111 changes: 65 additions & 46 deletions apps/game-db-updater/src/handlers/persistGameEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v6 as guid } from 'uuid'
import type { IHandlePublishedTopics } from '../IHandlePublishedTopics'
import { getDbClient } from '../dbClient'

const { isEmpty } = _
const { isEmpty, uniq } = _

const debug = createDebugger(
'playnite-web/game-db-updater/handler/persistGameEntities',
Expand Down Expand Up @@ -53,60 +53,79 @@ const handler: IHandlePublishedTopics = async (topic, payload) => {

if (isEmpty(consolidatedGames)) {
const id = guid()
await client.db('games').collection('consolidated-games').insertOne({
id,
name: entity.name,
releases: [],
description: entity.description,
playlists: [],
})
}

const releaseCursor = await client
.db('games')
.collection<{ name: string; releases: string[] }>('consolidated-games')
.aggregate([
{
$match: { name: entity.name },
},
{
$project: {
releases: {
$concatArrays: ['$releases', [entityId]],
},
},
},
])
for await (const doc of releaseCursor) {
await client
.db('games')
.collection('consolidated-games')
.insertOne({
id,
name: entity.name,
releases: [entityId],
description: entity.description,
playlists:
entity?.tags
?.filter((tag) => isPlaylistTag.test(tag.name))
?.map((tag) => tag.id) ?? [],
})
} else {
await client
.db('games')
.collection<{ releases: string[] }>('consolidated-games')
.updateOne({ name: entity.name }, { $push: { releases: entityId } })
const cursor = await client
.db('games')
.collection<{ name: string; releases: string[] }>(
.collection<{ name: string; releases: Array<string> }>(
'consolidated-games',
)
.aggregate([
.updateOne(
{ name: entity.name },
{
$match: { name: entity.name },
},
{
$project: {
playlists: {
$concatArrays:
entity?.tags
?.filter((tag) => isPlaylistTag.test(tag.name))
?.map((tag) => tag.id) ?? [],
},
$set: {
releases: uniq(doc.releases ?? []),
},
},
])
)
}

for await (const doc of cursor) {
await client
.db('games')
.collection<{ name: string; playlists: Array<string> }>(
'consolidated-games',
)
.updateOne(
{ name: entity.name },
{
$set: {
playlists: doc.playlists ?? [],
},
const playlists =
entity?.tags
?.filter((tag) => isPlaylistTag.test(tag.name))
?.map((tag) => tag.id) ?? []
const cursor = await client
.db('games')
.collection<{ name: string; releases: string[] }>('consolidated-games')
.aggregate([
{
$match: { name: entity.name },
},
{
$project: {
playlists: {
$concatArrays: ['$playlists', playlists],
},
)
}
},
},
])
for await (const doc of cursor) {
await client
.db('games')
.collection<{ name: string; playlists: Array<string> }>(
'consolidated-games',
)
.updateOne(
{ name: entity.name },
{
$set: {
playlists: uniq(doc.playlists ?? []),
},
},
)
}
}
} catch (e) {
Expand Down
12 changes: 8 additions & 4 deletions apps/playnite-web/cypress/e2e/homepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ describe('Homepage', () => {
cy.viewport(1366, 1080)
cy.visit('/')
cy.contains('h4', 'On Deck').parents('[data-test="playlist"]')
cy.get('[data-test="GameFigure"]').should('have.length', 8)
cy.get('[data-test="GameFigure"]').should('have.length', 9)
cy.get('[data-test="GameFigure"]')
.eq(0)
.should('have.text', 'Black Myth: Wukong')
.should('have.text', 'Star Ocean: The Second Story R')

cy.get('[data-test="playlist"] ul').compareSnapshot({
name: 'homepage-playing-playlist',
Expand All @@ -37,9 +37,13 @@ describe('Homepage', () => {
cy.get('[data-test="GameFigure"] span').eq(0).click({ force: true })
cy.get('[data-test="GameDetails"] h4').should(
'have.text',
'Black Myth: Wukong',
'Star Ocean: The Second Story R',
)
const description = `Black Myth: Wukong is an action RPG rooted in Chinese mythology. The story is based on Journey to the West, one of the Four Great Classical Novels of Chinese literature. You shall set out as the Destined One to venture into the challenges and marvels ahead, to uncover the obscured truth beneath the veil of a glorious legend from the past.`
const description = `Two worlds, one fateful encounter.
In an endless sea of stars, at the edge of the universe, two people who live in different worlds go on a journey to save planet Expel.
Choose your path and witness an awakened destiny.`
cy.get('[data-test="GameDetails"]').should('contain.text', description)
cy.get('[name="close-drawer"]').click()
cy.get('[data-test="GameDetails"]').should('not.exist')
Expand Down
2 changes: 1 addition & 1 deletion apps/playnite-web/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"executor": "nx:run-commands",
"options": {
"cwd": "{projectRoot}",
"command": "yarn cross-env NODE_ENV=development DEBUG='playnite-web/*' yarn node --experimental-json-modules scripts/utils/startDevServer.js"
"command": "yarn cross-env NODE_ENV=development yarn node --experimental-json-modules scripts/utils/startDevServer.js"
}
},
"test/unit": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ba6e63c

Please sign in to comment.