item controller: remove all synchronous fetching
This commit is contained in:
@@ -73,17 +73,10 @@ public class ItemController
|
|||||||
ItemEntry item = itemService.getItem(itemId);
|
ItemEntry item = itemService.getItem(itemId);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
response.setHeader(RUNELITE_CACHE, "HIT");
|
|
||||||
return item.toItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
item = itemService.fetchItem(itemId);
|
|
||||||
if (item != null)
|
|
||||||
{
|
|
||||||
response.setHeader(RUNELITE_CACHE, "MISS");
|
|
||||||
return item.toItem();
|
return item.toItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemService.queueItem(itemId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +120,6 @@ public class ItemController
|
|||||||
}
|
}
|
||||||
|
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
boolean hit = true;
|
|
||||||
|
|
||||||
if (time != null && time.isAfter(now))
|
if (time != null && time.isAfter(now))
|
||||||
{
|
{
|
||||||
@@ -137,16 +129,11 @@ public class ItemController
|
|||||||
ItemEntry item = itemService.getItem(itemId);
|
ItemEntry item = itemService.getItem(itemId);
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
item = itemService.fetchItem(itemId);
|
itemService.queueItem(itemId); // queue lookup
|
||||||
hit = false;
|
cachedEmpty.put(itemId, itemId); // cache empty
|
||||||
|
return ResponseEntity.notFound()
|
||||||
if (item == null)
|
.header(RUNELITE_CACHE, "MISS")
|
||||||
{
|
.build();
|
||||||
cachedEmpty.put(itemId, itemId);
|
|
||||||
return ResponseEntity.notFound()
|
|
||||||
.header(RUNELITE_CACHE, "MISS")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PriceEntry priceEntry = itemService.getPrice(itemId, time);
|
PriceEntry priceEntry = itemService.getPrice(itemId, time);
|
||||||
@@ -164,28 +151,18 @@ public class ItemController
|
|||||||
else if (priceEntry == null)
|
else if (priceEntry == null)
|
||||||
{
|
{
|
||||||
// Price is unknown
|
// Price is unknown
|
||||||
List<PriceEntry> prices = itemService.fetchPrice(itemId);
|
itemService.queuePriceLookup(itemId); // queue lookup
|
||||||
|
cachedEmpty.put(itemId, itemId);
|
||||||
if (prices == null || prices.isEmpty())
|
return ResponseEntity.notFound()
|
||||||
{
|
.header(RUNELITE_CACHE, "MISS")
|
||||||
cachedEmpty.put(itemId, itemId);
|
.build();
|
||||||
return ResponseEntity.notFound()
|
|
||||||
.header(RUNELITE_CACHE, "MISS")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the most recent price
|
|
||||||
priceEntry = prices.get(prices.size() - 1);
|
|
||||||
hit = false;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
Instant cacheTime = now.minus(CACHE_DUATION);
|
||||||
|
if (priceEntry.getFetched_time().isBefore(cacheTime))
|
||||||
{
|
{
|
||||||
Instant cacheTime = now.minus(CACHE_DUATION);
|
// Queue a check for the price
|
||||||
if (priceEntry.getFetched_time().isBefore(cacheTime))
|
itemService.queuePriceLookup(itemId);
|
||||||
{
|
|
||||||
// Queue a check for the price
|
|
||||||
itemService.queuePriceLookup(itemId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemPrice itemPrice = new ItemPrice();
|
ItemPrice itemPrice = new ItemPrice();
|
||||||
@@ -194,7 +171,6 @@ public class ItemController
|
|||||||
itemPrice.setTime(priceEntry.getTime());
|
itemPrice.setTime(priceEntry.getTime());
|
||||||
|
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.header(RUNELITE_CACHE, hit ? "HIT" : "MISS")
|
|
||||||
.cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic())
|
.cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic())
|
||||||
.body(itemPrice);
|
.body(itemPrice);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user