Migrate most things from item translations

Not the modeling code yet though!
This commit is contained in:
Emi Matchu 2024-02-20 16:27:05 -08:00
parent 6686f13154
commit 62531cfe34
7 changed files with 45 additions and 74 deletions

View file

@ -49,7 +49,7 @@ async function handle(req, res) {
// Modified, unless the data really did change.) // Modified, unless the data really did change.)
res.setHeader( res.setHeader(
"Cache-Control", "Cache-Control",
"public, max-age=3600, stale-while-revalidate=86400" "public, max-age=3600, stale-while-revalidate=86400",
); );
return res.send(itemValues); return res.send(itemValues);
} }
@ -58,11 +58,8 @@ async function loadAllNcItemNamesAndIds() {
const db = await connectToDb(); const db = await connectToDb();
const [rows] = await db.query(` const [rows] = await db.query(`
SELECT items.id, item_translations.name FROM items SELECT items.id, items.name FROM items
INNER JOIN item_translations ON item_translations.item_id = items.id WHERE items.rarity_index IN (0, 500) OR is_manually_nc = 1
WHERE
(items.rarity_index IN (0, 500) OR is_manually_nc = 1)
AND item_translations.locale = "en"
`); `);
return rows.map(({ id, name }) => ({ id, name: normalizeItemName(name) })); return rows.map(({ id, name }) => ({ id, name: normalizeItemName(name) }));
@ -75,13 +72,13 @@ async function loadAllNcItemNamesAndIds() {
*/ */
async function loadOWLSValuesByIdOrName() { async function loadOWLSValuesByIdOrName() {
const res = await fetch( const res = await fetch(
`https://neo-owls.herokuapp.com/itemdata/owls_script/` `https://neo-owls.herokuapp.com/itemdata/owls_script/`,
); );
const json = await res.json(); const json = await res.json();
if (!res.ok) { if (!res.ok) {
throw new Error( throw new Error(
`Could not load OWLS Pricer data: ${res.status} ${res.statusText}` `Could not load OWLS Pricer data: ${res.status} ${res.statusText}`,
); );
} }
@ -137,7 +134,7 @@ function normalizeItemName(name) {
async function handleWithBeeline(req, res) { async function handleWithBeeline(req, res) {
beeline.withTrace( beeline.withTrace(
{ name: "api/allNCTradeValues", operation_name: "api/allNCTradeValues" }, { name: "api/allNCTradeValues", operation_name: "api/allNCTradeValues" },
() => handle(req, res) () => handle(req, res),
); );
} }

View file

@ -115,8 +115,7 @@ async function handle(req, res) {
if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) { if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) {
try { try {
const { itemLoader, itemTranslationLoader, zoneLoader } = const { itemLoader, zoneLoader } = buildLoaders(db);
buildLoaders(db);
// Copied from setLayerBodyId mutation // Copied from setLayerBodyId mutation
const itemId = await db const itemId = await db
@ -127,9 +126,8 @@ async function handle(req, res) {
) )
.then(([rows]) => normalizeRow(rows[0]).parentId); .then(([rows]) => normalizeRow(rows[0]).parentId);
const [item, itemTranslation, zone, bodyName] = await Promise.all([ const [item, zone, bodyName] = await Promise.all([
itemLoader.load(itemId), itemLoader.load(itemId),
itemTranslationLoader.load(itemId),
zoneLoader.load(layer.zoneId), zoneLoader.load(layer.zoneId),
loadBodyName(layer.bodyId, db), loadBodyName(layer.bodyId, db),
]); ]);
@ -137,7 +135,7 @@ async function handle(req, res) {
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${item.name}`,
thumbnail: { thumbnail: {
url: item.thumbnailUrl, url: item.thumbnailUrl,
height: 80, height: 80,

View file

@ -1,6 +1,6 @@
yarn run --silent mysqldump openneo_impress species colors zones \ yarn run --silent mysqldump openneo_impress species colors zones \
> $(dirname $0)/../public-data-constants.sql \ > $(dirname $0)/../public-data-constants.sql \
&& yarn run --silent mysqldump openneo_impress alt_styles items item_translations \ && yarn run --silent mysqldump openneo_impress alt_styles items \
parents_swf_assets pet_states pet_types swf_assets \ parents_swf_assets pet_states pet_types swf_assets \
| gzip -c \ | gzip -c \
> $(dirname $0)/../public-data-from-modeling.sql.gz > $(dirname $0)/../public-data-from-modeling.sql.gz

View file

@ -1,6 +1,6 @@
yarn run --silent mysqldump --no-data openneo_impress closet_hangers closet_lists \ yarn run --silent mysqldump --no-data openneo_impress closet_hangers closet_lists \
colors items item_translations modeling_logs parents_swf_assets pet_types \ colors items modeling_logs parents_swf_assets pet_types pet_states species \
pet_states species swf_assets users zones \ swf_assets users zones \
| \ | \
sed 's/ AUTO_INCREMENT=[0-9]*//g' \ sed 's/ AUTO_INCREMENT=[0-9]*//g' \
> $(dirname $0)/../schema-for-impress.sql \ > $(dirname $0)/../schema-for-impress.sql \

View file

@ -7,7 +7,6 @@ GRANT SELECT ON colors TO impress2020;
GRANT SELECT ON donation_features TO impress2020; GRANT SELECT ON donation_features TO impress2020;
GRANT SELECT ON donations TO impress2020; GRANT SELECT ON donations TO impress2020;
GRANT SELECT ON items TO impress2020; GRANT SELECT ON items TO impress2020;
GRANT SELECT ON item_translations TO impress2020;
GRANT SELECT ON modeling_logs TO impress2020; GRANT SELECT ON modeling_logs TO impress2020;
GRANT SELECT ON parents_swf_assets TO impress2020; GRANT SELECT ON parents_swf_assets TO impress2020;
GRANT SELECT ON pet_types TO impress2020; GRANT SELECT ON pet_types TO impress2020;
@ -18,7 +17,6 @@ GRANT SELECT ON zones TO impress2020;
-- Public data tables: write. Used in modeling and support tools. -- Public data tables: write. Used in modeling and support tools.
GRANT INSERT, UPDATE ON items TO impress2020; GRANT INSERT, UPDATE ON items TO impress2020;
GRANT INSERT, UPDATE ON item_translations TO impress2020;
GRANT INSERT, UPDATE, DELETE ON parents_swf_assets TO impress2020; GRANT INSERT, UPDATE, DELETE ON parents_swf_assets TO impress2020;
GRANT INSERT, UPDATE ON pet_types TO impress2020; GRANT INSERT, UPDATE ON pet_types TO impress2020;
GRANT INSERT, UPDATE ON pet_states TO impress2020; GRANT INSERT, UPDATE ON pet_states TO impress2020;

View file

@ -316,15 +316,15 @@ const typeDefs = gql`
const resolvers = { const resolvers = {
Item: { Item: {
name: async ({ id, name }, _, { itemTranslationLoader }) => { name: async ({ id, name }, _, { itemLoader }) => {
if (name) return name; if (name) return name;
const translation = await itemTranslationLoader.load(id); const item = await itemLoader.load(id);
return translation.name; return item.name;
}, },
description: async ({ id, description }, _, { itemTranslationLoader }) => { description: async ({ id, description }, _, { itemLoader }) => {
if (description) return description; if (description) return description;
const translation = await itemTranslationLoader.load(id); const item = await itemLoader.load(id);
return translation.description; return item.description;
}, },
thumbnailUrl: async ({ id, thumbnailUrl }, _, { itemLoader }) => { thumbnailUrl: async ({ id, thumbnailUrl }, _, { itemLoader }) => {
if (thumbnailUrl) return thumbnailUrl; if (thumbnailUrl) return thumbnailUrl;
@ -340,15 +340,9 @@ const resolvers = {
const item = await itemLoader.load(id); const item = await itemLoader.load(id);
return isNC(item); return isNC(item);
}, },
isPb: async ({ id }, _, { itemTranslationLoader }) => { isPb: async ({ id }, _, { itemLoader }) => {
const translation = await itemTranslationLoader.load(id); const item = await itemLoader.load(id);
if (!translation) { return item.description.includes(
console.warn(
`Item.isPb: Translation not found for item ${id}. Returning false.`,
);
return false;
}
return translation.description.includes(
"This item is part of a deluxe paint brush set!", "This item is part of a deluxe paint brush set!",
); );
}, },
@ -360,20 +354,14 @@ const resolvers = {
// This feature is deprecated, so now we just always return unknown value. // This feature is deprecated, so now we just always return unknown value.
return null; return null;
}, },
ncTradeValueText: async ( ncTradeValueText: async ({ id }, _, { itemLoader }) => {
{ id },
_,
{ itemLoader, itemTranslationLoader },
) => {
// Skip this lookup for non-NC items, as a perf optimization. // Skip this lookup for non-NC items, as a perf optimization.
const item = await itemLoader.load(id); const item = await itemLoader.load(id);
if (!isNC(item)) { if (!isNC(item)) {
return; return;
} }
// Get the item name, which is how we look things up in ~owls. let itemName = item.name;
const itemTranslation = await itemTranslationLoader.load(id);
let itemName = itemTranslation.name;
// HACK: The name "Butterfly Dress" is used for two different items. // HACK: The name "Butterfly Dress" is used for two different items.
// Here's what ~owls does to distinguish! // Here's what ~owls does to distinguish!

View file

@ -104,7 +104,7 @@ const resolvers = {
setManualSpecialColor: async ( setManualSpecialColor: async (
_, _,
{ itemId, colorId, supportSecret }, { itemId, colorId, supportSecret },
{ itemLoader, itemTranslationLoader, colorLoader, db }, { itemLoader, colorLoader, db },
) => { ) => {
assertSupportSecretOrThrow(supportSecret); assertSupportSecretOrThrow(supportSecret);
@ -125,8 +125,7 @@ const resolvers = {
if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) { if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) {
try { try {
const [itemTranslation, oldColor, newColor] = await Promise.all([ const [oldColor, newColor] = await Promise.all([
itemTranslationLoader.load(itemId),
oldItem.manualSpecialColorId oldItem.manualSpecialColorId
? colorLoader.load(oldItem.manualSpecialColorId) ? colorLoader.load(oldItem.manualSpecialColorId)
: Promise.resolve(null), : Promise.resolve(null),
@ -142,7 +141,7 @@ const resolvers = {
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${oldItem.name}`,
thumbnail: { thumbnail: {
url: oldItem.thumbnailUrl, url: oldItem.thumbnailUrl,
height: 80, height: 80,
@ -172,7 +171,7 @@ const resolvers = {
setItemExplicitlyBodySpecific: async ( setItemExplicitlyBodySpecific: async (
_, _,
{ itemId, explicitlyBodySpecific, supportSecret }, { itemId, explicitlyBodySpecific, supportSecret },
{ itemLoader, itemTranslationLoader, db }, { itemLoader, db },
) => { ) => {
assertSupportSecretOrThrow(supportSecret); assertSupportSecretOrThrow(supportSecret);
@ -193,7 +192,6 @@ const resolvers = {
if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) { if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) {
try { try {
const itemTranslation = await itemTranslationLoader.load(itemId);
const oldRuleName = oldItem.explicitlyBodySpecific const oldRuleName = oldItem.explicitlyBodySpecific
? "Body specific" ? "Body specific"
: "Auto-detect"; : "Auto-detect";
@ -203,7 +201,7 @@ const resolvers = {
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${oldItem.name}`,
thumbnail: { thumbnail: {
url: oldItem.thumbnailUrl, url: oldItem.thumbnailUrl,
height: 80, height: 80,
@ -233,7 +231,7 @@ const resolvers = {
setItemIsManuallyNc: async ( setItemIsManuallyNc: async (
_, _,
{ itemId, isManuallyNc, supportSecret }, { itemId, isManuallyNc, supportSecret },
{ itemLoader, itemTranslationLoader, db }, { itemLoader, db },
) => { ) => {
assertSupportSecretOrThrow(supportSecret); assertSupportSecretOrThrow(supportSecret);
@ -254,7 +252,6 @@ const resolvers = {
if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) { if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) {
try { try {
const itemTranslation = await itemTranslationLoader.load(itemId);
const oldRuleName = oldItem.isManuallyNc const oldRuleName = oldItem.isManuallyNc
? "Manually set: Yes" ? "Manually set: Yes"
: "Auto-detect"; : "Auto-detect";
@ -264,7 +261,7 @@ const resolvers = {
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${oldItem.name}`,
thumbnail: { thumbnail: {
url: oldItem.thumbnailUrl, url: oldItem.thumbnailUrl,
height: 80, height: 80,
@ -294,7 +291,7 @@ const resolvers = {
setLayerBodyId: async ( setLayerBodyId: async (
_, _,
{ layerId, bodyId, supportSecret }, { layerId, bodyId, supportSecret },
{ itemLoader, itemTranslationLoader, swfAssetLoader, zoneLoader, db }, { itemLoader, swfAssetLoader, zoneLoader, db },
) => { ) => {
assertSupportSecretOrThrow(supportSecret); assertSupportSecretOrThrow(supportSecret);
@ -338,10 +335,8 @@ const resolvers = {
) )
.then(([rows]) => normalizeRow(rows[0]).parentId); .then(([rows]) => normalizeRow(rows[0]).parentId);
const [item, itemTranslation, zone, oldBodyName, newBodyName] = const [item, zone, oldBodyName, newBodyName] = await Promise.all([
await Promise.all([
itemLoader.load(itemId), itemLoader.load(itemId),
itemTranslationLoader.load(itemId),
zoneLoader.load(oldSwfAsset.zoneId), zoneLoader.load(oldSwfAsset.zoneId),
loadBodyName(oldSwfAsset.bodyId, db), loadBodyName(oldSwfAsset.bodyId, db),
loadBodyName(bodyId, db), loadBodyName(bodyId, db),
@ -350,7 +345,7 @@ const resolvers = {
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${item.name}`,
thumbnail: { thumbnail: {
url: item.thumbnailUrl, url: item.thumbnailUrl,
height: 80, height: 80,
@ -384,7 +379,6 @@ const resolvers = {
{ layerId, knownGlitches, supportSecret }, { layerId, knownGlitches, supportSecret },
{ {
itemLoader, itemLoader,
itemTranslationLoader,
swfAssetLoader, swfAssetLoader,
zoneLoader, zoneLoader,
petStateLoader, petStateLoader,
@ -439,16 +433,15 @@ const resolvers = {
.then(([rows]) => normalizeRow(rows[0])); .then(([rows]) => normalizeRow(rows[0]));
if (parentType === "Item") { if (parentType === "Item") {
const [item, itemTranslation, zone] = await Promise.all([ const [item, zone] = await Promise.all([
itemLoader.load(parentId), itemLoader.load(parentId),
itemTranslationLoader.load(parentId),
zoneLoader.load(oldSwfAsset.zoneId), zoneLoader.load(oldSwfAsset.zoneId),
]); ]);
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${item.name}`,
thumbnail: { thumbnail: {
url: item.thumbnailUrl, url: item.thumbnailUrl,
height: 80, height: 80,
@ -523,7 +516,7 @@ const resolvers = {
bulkAddLayersToItem: async ( bulkAddLayersToItem: async (
_, _,
{ itemId, entries, supportSecret }, { itemId, entries, supportSecret },
{ itemLoader, itemTranslationLoader, db }, { itemLoader, db },
) => { ) => {
assertSupportSecretOrThrow(supportSecret); assertSupportSecretOrThrow(supportSecret);
@ -562,12 +555,10 @@ const resolvers = {
if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) { if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) {
try { try {
const itemTranslation = await itemTranslationLoader.load(itemId);
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${item.name}`,
thumbnail: { thumbnail: {
url: item.thumbnailUrl, url: item.thumbnailUrl,
height: 80, height: 80,
@ -597,7 +588,7 @@ const resolvers = {
removeLayerFromItem: async ( removeLayerFromItem: async (
_, _,
{ layerId, itemId, supportSecret }, { layerId, itemId, supportSecret },
{ itemLoader, itemTranslationLoader, swfAssetLoader, zoneLoader, db }, { itemLoader, swfAssetLoader, zoneLoader, db },
) => { ) => {
assertSupportSecretOrThrow(supportSecret); assertSupportSecretOrThrow(supportSecret);
@ -620,9 +611,8 @@ const resolvers = {
if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) { if (process.env["SUPPORT_TOOLS_DISCORD_WEBHOOK_URL"]) {
try { try {
const [item, itemTranslation, zone, bodyName] = await Promise.all([ const [item, zone, bodyName] = await Promise.all([
itemLoader.load(itemId), itemLoader.load(itemId),
itemTranslationLoader.load(itemId),
zoneLoader.load(oldSwfAsset.zoneId), zoneLoader.load(oldSwfAsset.zoneId),
loadBodyName(oldSwfAsset.bodyId, db), loadBodyName(oldSwfAsset.bodyId, db),
]); ]);
@ -630,7 +620,7 @@ const resolvers = {
await logToDiscord({ await logToDiscord({
embeds: [ embeds: [
{ {
title: `🛠 ${itemTranslation.name}`, title: `🛠 ${item.name}`,
thumbnail: { thumbnail: {
url: item.thumbnailUrl, url: item.thumbnailUrl,
height: 80, height: 80,