Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix game library showing no games #503

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/game-db-updater/src/handlers/persistAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const create =
}

const client = await getDbClient()
await client
.db('games')
.collection('assets')
.createIndex({ relatedId: 1, typeKey: 1 }, { unique: true })

await client
.db('games')
.collection('assets')
Expand Down
108 changes: 52 additions & 56 deletions apps/game-db-updater/src/handlers/persistGameEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,24 @@ const handler: IHandlePublishedTopics = async (topic, payload) => {
.collection(collectionName)
.updateOne({ id: entityId }, { $set: entity }, { upsert: true })

await client
.db('games')
.createIndex(collectionName, { id: 1 }, { unique: true })
await client.db('games').createIndex(collectionName, { name: 1 })

if (collectionName === 'game') {
const consolidatedGames = await client
await client
.db('games')
.createIndex('consolidated-games', { id: 1 }, { unique: true })
await client
.db('games')
.createIndex('consolidated-games', { name: 1 }, { unique: true })
let consolidatedGame = await client
.db('games')
.collection('consolidated-games')
.find({ name: entity.name })
.toArray()
.findOne({ name: entity.name })

if (isEmpty(consolidatedGames)) {
if (!consolidatedGame) {
const id = guid()
await client.db('games').collection('consolidated-games').insertOne({
id,
Expand All @@ -62,71 +72,57 @@ const handler: IHandlePublishedTopics = async (topic, payload) => {
})
}

const releaseCursor = await client
consolidatedGame = await client
.db('games')
.collection<{ name: string; releases: string[] }>('consolidated-games')
.aggregate([
{
$match: { name: entity.name },
},
.collection<{
releases: string[]
playlists: string[]
}>('consolidated-games')
.findOne({ name: entity.name })

if (!consolidatedGame) {
console.error(
`Could not find consolidated game for game ${entity.name}`,
JSON.stringify(entity, null, 2),
)
return
}

await client
.db('games')
.collection<{ name: string; releases: Array<string> }>(
'consolidated-games',
)
.updateOne(
{ _id: consolidatedGame._id },
{
$project: {
releases: {
$concatArrays: ['$releases', [entityId]],
},
$set: {
releases: uniq(
[entityId].concat(consolidatedGame.releases ?? []),
),
},
},
])
for await (const doc of releaseCursor) {
await client
.db('games')
.collection<{ name: string; releases: Array<string> }>(
'consolidated-games',
)
.updateOne(
{ name: entity.name },
{
$set: {
releases: uniq(doc.releases ?? []),
},
},
)
}
)

const playlists =
entity?.tags
?.filter((tag) => isPlaylistTag.test(tag.name))
?.map((tag) => tag.id) ?? []
const cursor = await client
await client
.db('games')
.collection<{ name: string; releases: string[] }>('consolidated-games')
.aggregate([
.collection<{ name: string; playlists: Array<string> }>(
'consolidated-games',
)
.updateOne(
{ _id: consolidatedGame._id },
{
$match: { name: entity.name },
},
{
$project: {
playlists: {
$concatArrays: ['$playlists', playlists],
},
$set: {
playlists: uniq(
playlists.concat(consolidatedGame.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) {
console.error(e)
Expand Down
2 changes: 1 addition & 1 deletion changelog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
'issues',
'lerna',
],
scopes: ['api', 'ui', 'extension', 'misc'],
scopes: ['api', 'ui', 'extension', 'updater', 'misc'],
types: {
chore: {
description: 'Build process or auxiliary tool changes',
Expand Down
Loading