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.)
res.setHeader(
"Cache-Control",
"public, max-age=3600, stale-while-revalidate=86400"
"public, max-age=3600, stale-while-revalidate=86400",
);
return res.send(itemValues);
}
@ -58,11 +58,8 @@ async function loadAllNcItemNamesAndIds() {
const db = await connectToDb();
const [rows] = await db.query(`
SELECT items.id, item_translations.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)
AND item_translations.locale = "en"
SELECT items.id, items.name FROM items
WHERE items.rarity_index IN (0, 500) OR is_manually_nc = 1
`);
return rows.map(({ id, name }) => ({ id, name: normalizeItemName(name) }));
@ -75,13 +72,13 @@ async function loadAllNcItemNamesAndIds() {
*/
async function loadOWLSValuesByIdOrName() {
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();
if (!res.ok) {
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) {
beeline.withTrace(
{ 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"]) {
try {
const { itemLoader, itemTranslationLoader, zoneLoader } =
buildLoaders(db);
const { itemLoader, zoneLoader } = buildLoaders(db);
// Copied from setLayerBodyId mutation
const itemId = await db
@ -127,9 +126,8 @@ async function handle(req, res) {
)
.then(([rows]) => normalizeRow(rows[0]).parentId);
const [item, itemTranslation, zone, bodyName] = await Promise.all([
const [item, zone, bodyName] = await Promise.all([
itemLoader.load(itemId),
itemTranslationLoader.load(itemId),
zoneLoader.load(layer.zoneId),
loadBodyName(layer.bodyId, db),
]);
@ -137,7 +135,7 @@ async function handle(req, res) {
await logToDiscord({
embeds: [
{
title: `🛠 ${itemTranslation.name}`,
title: `🛠 ${item.name}`,
thumbnail: {
url: item.thumbnailUrl,
height: 80,

View file

@ -1,6 +1,6 @@
yarn run --silent mysqldump openneo_impress species colors zones \
> $(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 \
| gzip -c \
> $(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 \
colors items item_translations modeling_logs parents_swf_assets pet_types \
pet_states species swf_assets users zones \
colors items modeling_logs parents_swf_assets pet_types pet_states species \
swf_assets users zones \
| \
sed 's/ AUTO_INCREMENT=[0-9]*//g' \
> $(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 donations 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 parents_swf_assets 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.
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 ON pet_types TO impress2020;
GRANT INSERT, UPDATE ON pet_states TO impress2020;

View file

@ -316,15 +316,15 @@ const typeDefs = gql`
const resolvers = {
Item: {
name: async ({ id, name }, _, { itemTranslationLoader }) => {
name: async ({ id, name }, _, { itemLoader }) => {
if (name) return name;
const translation = await itemTranslationLoader.load(id);
return translation.name;
const item = await itemLoader.load(id);
return item.name;
},
description: async ({ id, description }, _, { itemTranslationLoader }) => {
description: async ({ id, description }, _, { itemLoader }) => {
if (description) return description;
const translation = await itemTranslationLoader.load(id);
return translation.description;
const item = await itemLoader.load(id);
return item.description;
},
thumbnailUrl: async ({ id, thumbnailUrl }, _, { itemLoader }) => {
if (thumbnailUrl) return thumbnailUrl;
@ -340,15 +340,9 @@ const resolvers = {
const item = await itemLoader.load(id);
return isNC(item);
},
isPb: async ({ id }, _, { itemTranslationLoader }) => {
const translation = await itemTranslationLoader.load(id);
if (!translation) {
console.warn(
`Item.isPb: Translation not found for item ${id}. Returning false.`,
);
return false;
}
return translation.description.includes(
isPb: async ({ id }, _, { itemLoader }) => {
const item = await itemLoader.load(id);
return item.description.includes(
"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.
return null;
},
ncTradeValueText: async (
{ id },
_,
{ itemLoader, itemTranslationLoader },
) => {
ncTradeValueText: async ({ id }, _, { itemLoader }) => {
// Skip this lookup for non-NC items, as a perf optimization.
const item = await itemLoader.load(id);
if (!isNC(item)) {
return;
}
// Get the item name, which is how we look things up in ~owls.
const itemTranslation = await itemTranslationLoader.load(id);
let itemName = itemTranslation.name;
let itemName = item.name;
// HACK: The name "Butterfly Dress" is used for two different items.
// Here's what ~owls does to distinguish!

View file

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