Merge branch 'main' of github.com:matchu/impress-2020 into main

This commit is contained in:
Emi Matchu 2021-08-07 21:44:37 -07:00
commit 30e6c46d48
3 changed files with 62 additions and 17 deletions

View file

@ -386,6 +386,18 @@ function NewItemsSectionContent() {
id id
name name
} }
babySpeciesThatNeedModels: speciesThatNeedModels(colorId: "6") {
id
name
}
maraquanSpeciesThatNeedModels: speciesThatNeedModels(colorId: "44") {
id
name
}
mutantSpeciesThatNeedModels: speciesThatNeedModels(colorId: "46") {
id
name
}
compatibleBodiesAndTheirZones { compatibleBodiesAndTheirZones {
body { body {
id id
@ -492,10 +504,16 @@ function ItemModelingSummary({ item }) {
// NOTE: To test this logic, I like to swap out `newestItems` in the query: // NOTE: To test this logic, I like to swap out `newestItems` in the query:
// `newestItems: items(ids: ["81546", "35082", "75149", "81797", "58741", "78953", "82427", "82727", "82726"])` // `newestItems: items(ids: ["81546", "35082", "75149", "81797", "58741", "78953", "82427", "82727", "82726"])`
if (item.speciesThatNeedModels.length > 0) { const numModelsNeeded =
item.speciesThatNeedModels.length +
item.babySpeciesThatNeedModels.length +
item.maraquanSpeciesThatNeedModels.length +
item.mutantSpeciesThatNeedModels.length;
if (numModelsNeeded > 0) {
return ( return (
<Box fontSize="xs" fontStyle="italic" fontWeight="600" opacity="0.8"> <Box fontSize="xs" fontStyle="italic" fontWeight="600" opacity="0.8">
Need {item.speciesThatNeedModels.length} models Need {numModelsNeeded} models
</Box> </Box>
); );
} }

View file

@ -58,6 +58,12 @@ const typePolicies = {
// it! This helps for fast loading when switching between standard // it! This helps for fast loading when switching between standard
// colors. // colors.
const { speciesId, colorId } = args; const { speciesId, colorId } = args;
console.debug(
"[appearanceOn] seeking cached appearance",
speciesId,
colorId,
readField("id")
);
const speciesStandardBodyId = readField( const speciesStandardBodyId = readField(
"standardBodyId", "standardBodyId",
toReference({ __typename: "Species", id: speciesId }) toReference({ __typename: "Species", id: speciesId })
@ -71,16 +77,22 @@ const typePolicies = {
// be loading them, depending on the page? Either way, return // be loading them, depending on the page? Either way, return
// `undefined`, meaning we don't know how to serve this from cache. // `undefined`, meaning we don't know how to serve this from cache.
// This will cause us to start loading it from the server. // This will cause us to start loading it from the server.
console.debug("[appearanceOn] species/colors not loaded yet");
return undefined; return undefined;
} }
if (colorIsStandard) { if (colorIsStandard) {
const itemId = readField("id"); const itemId = readField("id");
console.debug(
"[appearanceOn] standard color, will read:",
`item-${itemId}-body-${speciesStandardBodyId}`
);
return toReference({ return toReference({
__typename: "ItemAppearance", __typename: "ItemAppearance",
id: `item-${itemId}-body-${speciesStandardBodyId}`, id: `item-${itemId}-body-${speciesStandardBodyId}`,
}); });
} else { } else {
console.debug("[appearanceOn] non-standard color, failure");
// This isn't a standard color, so we don't support special // This isn't a standard color, so we don't support special
// cross-color caching for it. Return `undefined`, meaning we don't // cross-color caching for it. Return `undefined`, meaning we don't
// know how to serve this from cache. This will cause us to start // know how to serve this from cache. This will cause us to start

View file

@ -308,10 +308,25 @@ function buildItemSearchConditions({
// Split the query into words, and search for each word as a substring // Split the query into words, and search for each word as a substring
// of the name. // of the name.
const words = query.split(/\s+/); const words = query.split(/\s+/);
const wordMatchersForMysql = words.map( const wordMatchConditions = [];
(word) => "%" + word.replace(/_%/g, "\\$0") + "%" const wordMatchValues = [];
); for (let word of words) {
const matcherPlaceholders = words.map((_) => "t.name LIKE ?").join(" AND "); // If the word starts with `-`, remove `-` and treat the filter as negative.
const isNegative = word.startsWith("-");
if (isNegative) {
word = word.substr(1);
}
if (!word) {
continue;
}
const condition = isNegative ? "t.name NOT LIKE ?" : "t.name LIKE ?";
const matcher = "%" + word.replace(/_%/g, "\\$0") + "%";
wordMatchConditions.push(condition);
wordMatchValues.push(matcher);
}
const wordMatchCondition = wordMatchConditions.join(" AND ") || "1";
const itemKindCondition = itemSearchKindConditions[itemKind] || "1"; const itemKindCondition = itemSearchKindConditions[itemKind] || "1";
const bodyIdCondition = bodyId const bodyIdCondition = bodyId
@ -333,20 +348,20 @@ function buildItemSearchConditions({
: []; : [];
const queryJoins = ` const queryJoins = `
INNER JOIN item_translations t ON t.item_id = items.id INNER JOIN item_translations t ON t.item_id = items.id
INNER JOIN parents_swf_assets rel INNER JOIN parents_swf_assets rel
ON rel.parent_type = "Item" AND rel.parent_id = items.id ON rel.parent_type = "Item" AND rel.parent_id = items.id
INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id INNER JOIN swf_assets ON rel.swf_asset_id = swf_assets.id
${currentUserJoin} ${currentUserJoin}
`; `;
const queryConditions = ` const queryConditions = `
(${matcherPlaceholders}) AND t.locale = "en" AND (${wordMatchCondition}) AND (${bodyIdCondition}) AND
(${bodyIdCondition}) AND (${zoneIdsCondition}) AND (${zoneIdsCondition}) AND (${itemKindCondition}) AND
(${itemKindCondition}) AND (${currentUserCondition}) (${currentUserCondition}) AND t.locale = "en"
`; `;
const queryConditionValues = [ const queryConditionValues = [
...wordMatchersForMysql, ...wordMatchValues,
...bodyIdValues, ...bodyIdValues,
...zoneIds, ...zoneIds,
...currentUserValues, ...currentUserValues,