Skip to content

Commit

Permalink
feat: Make All Worlds Discoverable Proposal (#361)
Browse files Browse the repository at this point in the history
* remove hidden condition from queries

* remove disclaimer

* added migration to remove the hidden column

* remove hidden from schemas and queries

* remove task

* move dropColumn after dropIndex calls

* linted and fixed tests

* Update src/migrations/1697479763911_make-all-words-discoverable.ts

Co-authored-by: Braian Mellor <braianj@gmail.com>
Signed-off-by: Monotributista <140657302+contribuyente@users.noreply.github.com>

---------

Signed-off-by: Braian Mellor <braianj@gmail.com>
Signed-off-by: Monotributista <140657302+contribuyente@users.noreply.github.com>
Co-authored-by: Braian Mellor <braianj@gmail.com>
  • Loading branch information
contribuyente and braianj authored Oct 19, 2023
1 parent 96fe8bf commit bd0e6b6
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 238 deletions.
1 change: 0 additions & 1 deletion src/__data__/placeGenesisPlaza.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ export const placeGenesisPlaza: PlaceAttributes = {
created_at: new Date("2023-03-28T18:37:39.918Z"),
disabled_at: null,
deployed_at: new Date("2022-11-14T17:22:05.307Z"),
hidden: false,
textsearch: undefined,
categories: [],
}
1 change: 0 additions & 1 deletion src/__data__/placeGenesisPlazaWithAggregatedAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,5 @@ export const placeGenesisPlazaWithAggregatedAttributes: AggregatePlaceAttributes
world: false,
world_name: null,
deployed_at: new Date("2022-11-14T17:22:05.307Z"),
hidden: false,
textsearch: undefined,
}
1 change: 0 additions & 1 deletion src/__data__/placeRoad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const placeRoad: PlaceAttributes = {
created_at: new Date("2023-03-28T18:37:39.918Z"),
disabled_at: null,
deployed_at: new Date("2022-11-14T17:22:05.307Z"),
hidden: false,
textsearch: undefined,
categories: [],
}
3 changes: 0 additions & 3 deletions src/__data__/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const worldPlaceParalax: PlaceAttributes = {
world: true,
world_name: "paralax.dcl.eth",
deployed_at: new Date("2023-03-28T13:05:45.437Z"),
hidden: false,
textsearch: undefined,
categories: [],
}
Expand Down Expand Up @@ -67,7 +66,6 @@ export const worldPlaceParalaxWithAggregated: AggregatePlaceAttributes = {
world: true,
world_name: "paralax.dcl.eth",
deployed_at: new Date("2023-03-28T13:05:45.437Z"),
hidden: false,
user_favorite: false,
user_like: false,
user_dislike: false,
Expand Down Expand Up @@ -273,7 +271,6 @@ export const worldPlaceTemplegame: AggregatePlaceAttributes = {
world: true,
world_name: "templegame.dcl.eth",
deployed_at: new Date("2023-05-16T15:44:26.395Z"),
hidden: false,
user_favorite: false,
user_like: false,
user_dislike: false,
Expand Down
1 change: 0 additions & 1 deletion src/entities/CheckScenes/task/processContentEntityScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export function createPlaceFromContentEntityScene(
updated_at: now,
world: !!contentEntityScene?.metadata?.worldConfiguration,
world_name: worldName,
hidden: !!contentEntityScene?.metadata?.worldConfiguration,
...data,
title: title ? title.slice(0, 50) : "Untitled",
description: contentEntityScene?.metadata?.display?.description || null,
Expand Down
1 change: 0 additions & 1 deletion src/entities/CheckScenes/task/processEntityId.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ContentServer from "decentraland-gatsby/dist/utils/api/ContentServer"

import { contentEntitySceneGenesisPlaza } from "../../../__data__/contentEntitySceneGenesisPlaza"
import { exampleContentEntityProfile } from "../../../__data__/entities"
import {
sqsMessage,
sqsMessageProfile,
Expand Down
6 changes: 0 additions & 6 deletions src/entities/CheckScenes/task/taskRunnerSqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
notifyNewPlace,
notifyUpdatePlace,
} from "../../Slack/utils"
import { verifyWorldsIndexing } from "../../World/task/verifyWorldsIndexing"
import CheckScenesModel from "../model"
import { CheckSceneLogsTypes } from "../types"
import { getWorldAbout } from "../utils"
Expand Down Expand Up @@ -41,7 +40,6 @@ const placesAttributes: Array<keyof PlaceAttributes> = [
"deployed_at",
"world",
"world_name",
"hidden",
"textsearch",
]

Expand Down Expand Up @@ -70,13 +68,10 @@ export async function taskRunnerSqs(job: DeploymentToSqs) {

const worlds = await PlaceModel.findEnabledWorldName(worldName)

const worldIndexing = await verifyWorldsIndexing([worldName])

if (!worlds.length) {
const placefromContentEntity = createPlaceFromContentEntityScene(
contentEntityScene,
{
hidden: !worldIndexing[0].shouldBeIndexed,
disabled:
!!contentEntityScene?.metadata?.worldConfiguration?.placesConfig
?.optOut,
Expand Down Expand Up @@ -114,7 +109,6 @@ export async function taskRunnerSqs(job: DeploymentToSqs) {
contentEntityScene,
{
...worlds[0],
hidden: !worldIndexing[0].shouldBeIndexed,
disabled:
!!contentEntityScene?.metadata?.worldConfiguration?.placesConfig
?.optOut,
Expand Down
1 change: 0 additions & 1 deletion src/entities/Place/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export function createPlaceFromEntityScene(
deployed_at: now,
world: false,
world_name: null,
hidden: false,
categories: [],
textsearch: undefined,
...data,
Expand Down
60 changes: 8 additions & 52 deletions src/entities/Place/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const placesAttributes: Array<keyof PlaceAttributes> = [
"deployed_at",
"world",
"world_name",
"hidden",
]

const namedQuery = jest.spyOn(PlaceModel, "namedQuery")
Expand Down Expand Up @@ -526,8 +525,8 @@ describe(`insertPlace`, () => {
expect(name).toBe("insert_place")
expect(sql.text.trim().replace(/\s{2,}/gi, " ")).toEqual(
`
INSERT INTO "places" ("title", "description", "image", "owner", "positions", "base_position", "contact_name", "contact_email", "content_rating", "disabled", "disabled_at", "created_at", "updated_at", "deployed_at", "world", "world_name", "hidden", "id")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
INSERT INTO "places" ("title", "description", "image", "owner", "positions", "base_position", "contact_name", "contact_email", "content_rating", "disabled", "disabled_at", "created_at", "updated_at", "deployed_at", "world", "world_name", "id")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
`
.trim()
.replace(/\s{2,}/gi, " ")
Expand All @@ -546,11 +545,11 @@ describe(`updatePlace`, () => {
expect(name).toBe("update_place")
expect(sql.text.trim().replace(/\s{2,}/gi, " ")).toEqual(
`
UPDATE "places" SET "title" = $1, "description" = $2, "image" = $3, "owner" = $4, "positions" = $5, "base_position" = $6, "contact_name" = $7, "contact_email" = $8, "content_rating" = $9, "disabled" = $10, "disabled_at" = $11, "updated_at" = $12, "deployed_at" = $13, "world" = $14, "world_name" = $15, "hidden" = $16
UPDATE "places" SET "title" = $1, "description" = $2, "image" = $3, "owner" = $4, "positions" = $5, "base_position" = $6, "contact_name" = $7, "contact_email" = $8, "content_rating" = $9, "disabled" = $10, "disabled_at" = $11, "updated_at" = $12, "deployed_at" = $13, "world" = $14, "world_name" = $15
WHERE disabled is false AND world is false AND "base_position" IN
(
SELECT DISTINCT("base_position")
FROM "place_positions" "pp" WHERE "pp"."position" = $17
FROM "place_positions" "pp" WHERE "pp"."position" = $16
)
`
.trim()
Expand Down Expand Up @@ -605,7 +604,6 @@ describe(`findWorld`, () => {
WHERE
p.disabled is false
AND world is true
AND hidden is false
AND world_name IN ($1)
ORDER BY p.like_score DESC NULLS LAST, p."deployed_at" DESC
LIMIT $2
Expand Down Expand Up @@ -650,7 +648,6 @@ describe(`findWorld`, () => {
WHERE
p.disabled is false
AND world is true
AND hidden is false
AND world_name IN ($4)
AND rank > 0
ORDER BY rank DESC, p.like_score DESC NULLS LAST, p."deployed_at" DESC
Expand Down Expand Up @@ -701,7 +698,6 @@ describe(`countWorlds`, () => {
WHERE
p.disabled is false
AND p.world is true
AND p.hidden is false
AND p.world_name IN ($1)
`
.trim()
Expand Down Expand Up @@ -729,7 +725,6 @@ describe(`countWorlds`, () => {
WHERE
p.disabled is false
AND p.world is true
AND p.hidden is false
AND p.world_name IN ($2)
AND rank > 0
`
Expand Down Expand Up @@ -772,8 +767,8 @@ describe(`insertPlace`, () => {
expect(name).toBe("insert_place")
expect(sql.text.trim().replace(/\s{2,}/gi, " ")).toEqual(
`
INSERT INTO "places" ("title", "description", "image", "owner", "positions", "base_position", "contact_name", "contact_email", "content_rating", "disabled", "disabled_at", "created_at", "updated_at", "deployed_at", "world", "world_name", "hidden", "id")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
INSERT INTO "places" ("title", "description", "image", "owner", "positions", "base_position", "contact_name", "contact_email", "content_rating", "disabled", "disabled_at", "created_at", "updated_at", "deployed_at", "world", "world_name", "id")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
`
.trim()
.replace(/\s{2,}/gi, " ")
Expand All @@ -792,54 +787,15 @@ describe(`updatePlace`, () => {
expect(name).toBe("update_place")
expect(sql.text.trim().replace(/\s{2,}/gi, " ")).toEqual(
`
UPDATE "places" SET "title" = $1, "description" = $2, "image" = $3, "owner" = $4, "positions" = $5, "base_position" = $6, "contact_name" = $7, "contact_email" = $8, "content_rating" = $9, "disabled" = $10, "disabled_at" = $11, "updated_at" = $12, "deployed_at" = $13, "world" = $14, "world_name" = $15, "hidden" = $16
UPDATE "places" SET "title" = $1, "description" = $2, "image" = $3, "owner" = $4, "positions" = $5, "base_position" = $6, "contact_name" = $7, "contact_email" = $8, "content_rating" = $9, "disabled" = $10, "disabled_at" = $11, "updated_at" = $12, "deployed_at" = $13, "world" = $14, "world_name" = $15
WHERE disabled is false AND world is false AND "base_position" IN
(
SELECT DISTINCT("base_position")
FROM "place_positions" "pp" WHERE "pp"."position" = $17
FROM "place_positions" "pp" WHERE "pp"."position" = $16
)
`
.trim()
.replace(/\s{2,}/gi, " ")
)
})
})

describe(`updateWorldsShown`, () => {
test(`should not update a empty list`, async () => {
namedRowCount.mockResolvedValue(0)
expect(
await PlaceModel.updateIndexWorlds([
{
dclName: "paralax.dcl.eth",
shouldBeIndexed: true,
},
])
).toEqual(0)
expect(namedQuery.mock.calls.length).toBe(0)
})
test(`should update a list of world's names`, async () => {
namedRowCount.mockResolvedValue(1)
expect(
await PlaceModel.updateIndexWorlds([
{
dclName: "paralax.dcl.eth",
shouldBeIndexed: true,
},
])
).toEqual(1)
expect(namedRowCount.mock.calls.length).toBe(1)
const [name, sql] = namedRowCount.mock.calls[0]
expect(name).toBe("update_index_world")
expect(sql.text.trim().replace(/\s{2,}/gi, " ")).toEqual(
`
UPDATE "places" SET hidden = (world_name not in ($1)),
updated_at = now()
WHERE world is true
AND world_name IN ($2)
`
.trim()
.replace(/\s{2,}/gi, " ")
)
})
})
28 changes: 1 addition & 27 deletions src/entities/Place/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,31 +437,6 @@ export default class PlaceModel extends Model<PlaceAttributes> {
return this.namedQuery("find_worlds", sql)
}

static updateIndexWorlds = (
worlds: {
dclName: string
shouldBeIndexed: boolean
}[]
) => {
if (!worlds || worlds.length === 0) {
return 0
}

const names = worlds.map((world) => world.dclName)
const namesVisible = worlds
.filter((world) => world.shouldBeIndexed)
.map((world) => world.dclName)

const sql = SQL`
UPDATE ${table(this)} SET hidden = (world_name not in ${values(
namesVisible
)}), updated_at = now()
WHERE world is true
AND world_name IN ${values(names)}
`
return this.namedRowCount("update_index_world", sql)
}

static async findWorld(
options: FindWorldWithAggregatesOptions
): Promise<AggregatePlaceAttributes[]> {
Expand Down Expand Up @@ -521,7 +496,7 @@ export default class PlaceModel extends Model<PlaceAttributes> {
)})) as rank`
)}
WHERE
p.disabled is false AND world is true AND hidden is false
p.disabled is false AND world is true
${conditional(
options.names.length > 0,
SQL`AND world_name IN ${values(options.names)}`
Expand Down Expand Up @@ -569,7 +544,6 @@ export default class PlaceModel extends Model<PlaceAttributes> {
WHERE
p.disabled is false
AND p.world is true
AND p.hidden is false
${conditional(
options.names.length > 0,
SQL`AND p.world_name IN ${values(options.names)}`
Expand Down
4 changes: 0 additions & 4 deletions src/entities/Place/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ export const placeSchema = schema({
type: "string",
format: "date-time",
},
hidden: {
type: "boolean",
description: "True if the place is hidden",
},
user_like: {
type: "boolean",
description: "True if user likes the place",
Expand Down
1 change: 0 additions & 1 deletion src/entities/Place/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export type PlaceAttributes = {
updated_at: Date
world: boolean
world_name: string | null
hidden: boolean
deployed_at: Date
textsearch: SQLStatement | string | null | undefined
categories: string[]
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Place/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { SceneStats, SceneStatsMap } from "../../api/DataTeam"
import toCanonicalPosition from "../../utils/position/toCanonicalPosition"
import {
AggregatePlaceAttributes,
HotScene,
PlaceAttributes,
unwantedThumbnailHash,
HotScene,
} from "./types"

const DECENTRALAND_URL =
Expand Down
22 changes: 6 additions & 16 deletions src/entities/Slack/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ export async function notifyNewPlace(place: PlaceAttributes) {
type: "section",
text: {
type: "mrkdwn",
text: `:tada: New ${
place.world ? `world ${place.hidden ? "(hidden)" : ""}` : "place"
} added: ${
text: `:tada: New ${place.world ? "world" : "place"} added: ${
place.world
? place.hidden
? place.world_name
: `<${worldUrl(place)}|${place.world_name}>`
? `<${worldUrl(place)}|${place.world_name}>`
: `<${placeUrl(place)}|${place.base_position}>`
}`,
},
Expand Down Expand Up @@ -64,12 +60,10 @@ export async function notifyUpdatePlace(place: PlaceAttributes) {
text: {
type: "mrkdwn",
text: `:white_check_mark: ${
place.world ? `world ${place.hidden ? "(hidden)" : ""}` : "Place"
place.world ? "world" : "Place"
} updated: ${
place.world
? place.hidden
? place.world_name
: `<${worldUrl(place)}|${place.world_name}>`
? `<${worldUrl(place)}|${place.world_name}>`
: `<${placeUrl(place)}|${place.base_position}>`
}`,
},
Expand Down Expand Up @@ -194,9 +188,7 @@ export async function notifyDowngradeRating(
place.world ? "world" : "place"
} updated trying to downgrade rating: ${
place.world
? place.hidden
? place.world_name
: `<${worldUrl(place)}|${place.world_name}>`
? `<${worldUrl(place)}|${place.world_name}>`
: `<${placeUrl(place)}|${place.base_position}>`
}`,
},
Expand Down Expand Up @@ -229,9 +221,7 @@ export async function notifyUpgradingRating(
place.world ? "world" : "place"
} upgrade rating: ${
place.world
? place.hidden
? place.world_name
: `<${worldUrl(place)}|${place.world_name}>`
? `<${worldUrl(place)}|${place.world_name}>`
: `<${placeUrl(place)}|${place.base_position}>`
}`,
},
Expand Down
4 changes: 0 additions & 4 deletions src/entities/World/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ export const worldSchema = schema({
type: "string",
format: "date-time",
},
hidden: {
type: "boolean",
description: "True if the world is hidden",
},
user_like: {
type: "boolean",
description: "True if user likes the world",
Expand Down
12 changes: 0 additions & 12 deletions src/entities/World/task/checkWorldsIndexingTask.ts

This file was deleted.

Loading

0 comments on commit bd0e6b6

Please sign in to comment.