From 86738aee00be4b5c666ac88c8ea7659bbd27e0ca Mon Sep 17 00:00:00 2001 From: Kara <49822414+karashiiro@users.noreply.github.com> Date: Sun, 21 Jul 2024 13:40:49 -0700 Subject: [PATCH] Read materia into POCO directly (#1342) --- .../MarketBoard/ListingStore.cs | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/Universalis.DbAccess/MarketBoard/ListingStore.cs b/src/Universalis.DbAccess/MarketBoard/ListingStore.cs index 20b92f0a..343c2964 100644 --- a/src/Universalis.DbAccess/MarketBoard/ListingStore.cs +++ b/src/Universalis.DbAccess/MarketBoard/ListingStore.cs @@ -201,7 +201,7 @@ ORDER BY unit_price WorldId = reader.GetInt32(2), Hq = reader.GetBoolean(3), OnMannequin = reader.GetBoolean(4), - Materia = ReadMateriaFromReader(reader, query.WorldId, query.ItemId), + Materia = ReadMateriaFromReader(reader), PricePerUnit = reader.GetInt32(6), Quantity = reader.GetInt32(7), DyeId = reader.GetInt32(8), @@ -305,7 +305,7 @@ FROM listing t WorldId = worldId, Hq = reader.GetBoolean(3), OnMannequin = reader.GetBoolean(4), - Materia = ReadMateriaFromReader(reader, worldId, itemId), + Materia = ReadMateriaFromReader(reader), PricePerUnit = reader.GetInt32(6), Quantity = reader.GetInt32(7), DyeId = reader.GetInt32(8), @@ -449,30 +449,10 @@ private static JArray ConvertMateriaToJArray(IList materia) }); } - private List ReadMateriaFromReader(NpgsqlDataReader reader, int worldId, int itemId) + private static List ReadMateriaFromReader(NpgsqlDataReader reader) { return reader.IsDBNull(5) ? new List() - : ConvertMateriaFromJArray(reader.GetFieldValue(5), worldId, itemId); - } - - private List ConvertMateriaFromJArray(IEnumerable materia, int worldId, int itemId) - { - return materia - .Select((m, i) => - { - try - { - return new Materia { SlotId = m["slot_id"].Value(), MateriaId = m["materia_id"].Value() }; - } - catch (ArgumentException e) - { - // Unsure why this happens, possibly inserted bad data at some point while debugging - _logger.LogError(e, "Failed to parse materia for world={}, item={}", worldId, itemId); - return null; - } - }) - .Where(m => m is not null) - .ToList(); + : reader.GetFieldValue>(5); } } \ No newline at end of file