@@ -32,18 +32,25 @@ function M.modLineValue(line)
3232 return tonumber (line :match (" %-?[%d]+%.?[%d]*" ))
3333end
3434
35+ local _tradeStats
36+
3537--- @return table ? tradeStats
3638function M .getTradeStats ()
39+ if _tradeStats then return _tradeStats end
3740 local file = io.open (" ./Data/trade_site_stats.json" )
3841 if not file then return nil end
3942 local fileContents = file :read (" *a" )
4043 local parsed = dkjson .decode (fileContents )
41- return parsed and parsed .result
44+ _tradeStats = parsed and parsed .result
45+ return _tradeStats
4246end
4347
48+ local _optionTradeStatMap
49+
4450--- @param tradeStats table table of data from https : //www.pathofexile.com /api /trade2 /data /stats
4551--- @return table optionTradeStatMap table containing helper data for matching trade option filters
4652local function getOptionTradeStatMap (tradeStats )
53+ if _optionTradeStatMap then return _optionTradeStatMap end
4754 local optionTradeStatMap = {}
4855 for _ , cat in ipairs (tradeStats ) do
4956 if cat .id == " enchant" or cat .id == " explicit" or cat .id == " implicit" then
@@ -62,7 +69,8 @@ local function getOptionTradeStatMap(tradeStats)
6269 end
6370 end
6471 end
65- return optionTradeStatMap
72+ _optionTradeStatMap = optionTradeStatMap
73+ return _optionTradeStatMap
6674end
6775
6876-- Map source types used in OpenBuySimilarPopup to trade API category labels
@@ -152,8 +160,6 @@ function M.formatDatabaseText(text)
152160 return text
153161end
154162
155- local tradeStats = M .getTradeStats ()
156- local optionTradeStatMap = getOptionTradeStatMap (tradeStats )
157163
158164-- Helper: find the trade stat ID for a mod line
159165--- @param item table
@@ -191,7 +197,9 @@ function M.findTradeHash(item, modLine, modType, isDesecrated)
191197 end
192198 end
193199
194- if not tradeStats then return end
200+ local tradeStats = M .getTradeStats ()
201+ local optionTradeStatMap = getOptionTradeStatMap (tradeStats )
202+ if not tradeStats or not optionTradeStatMap then return end
195203
196204 for _ , v in ipairs (optionTradeStatMap [modType ] or {}) do
197205 if v .pattern then
0 commit comments