http service: remove unused price endpoints
Also remove time from ItemPrice, which is no longer needed now that the endpoint for fetching historic price data is gone
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.api.item;
|
package net.runelite.http.api.item;
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -33,5 +32,4 @@ public class ItemPrice
|
|||||||
private int id;
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
private int price;
|
private int price;
|
||||||
private Instant time;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,26 +29,19 @@ import com.google.common.base.Suppliers;
|
|||||||
import com.google.common.hash.HashCode;
|
import com.google.common.hash.HashCode;
|
||||||
import com.google.common.hash.Hasher;
|
import com.google.common.hash.Hasher;
|
||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import net.runelite.http.api.item.ItemPrice;
|
import net.runelite.http.api.item.ItemPrice;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.CacheControl;
|
import org.springframework.http.CacheControl;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/item")
|
@RequestMapping("/item")
|
||||||
public class ItemController
|
public class ItemController
|
||||||
{
|
{
|
||||||
private static final int MAX_BATCH_LOOKUP = 1024;
|
|
||||||
|
|
||||||
private static class MemoizedPrices
|
private static class MemoizedPrices
|
||||||
{
|
{
|
||||||
final ItemPrice[] prices;
|
final ItemPrice[] prices;
|
||||||
@@ -84,79 +77,11 @@ public class ItemController
|
|||||||
itemPrice.setId(priceEntry.getItem());
|
itemPrice.setId(priceEntry.getItem());
|
||||||
itemPrice.setName(priceEntry.getName());
|
itemPrice.setName(priceEntry.getName());
|
||||||
itemPrice.setPrice(priceEntry.getPrice());
|
itemPrice.setPrice(priceEntry.getPrice());
|
||||||
itemPrice.setTime(priceEntry.getTime());
|
|
||||||
return itemPrice;
|
return itemPrice;
|
||||||
})
|
})
|
||||||
.toArray(ItemPrice[]::new)), 30, TimeUnit.MINUTES);
|
.toArray(ItemPrice[]::new)), 30, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{itemId}/price")
|
|
||||||
public ResponseEntity<ItemPrice> itemPrice(
|
|
||||||
@PathVariable int itemId,
|
|
||||||
@RequestParam(required = false) Instant time
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Instant now = Instant.now();
|
|
||||||
|
|
||||||
if (time != null && time.isAfter(now))
|
|
||||||
{
|
|
||||||
time = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
PriceEntry priceEntry = itemService.getPrice(itemId, time);
|
|
||||||
|
|
||||||
if (time != null)
|
|
||||||
{
|
|
||||||
if (priceEntry == null)
|
|
||||||
{
|
|
||||||
// we maybe can't backfill this
|
|
||||||
return ResponseEntity.notFound()
|
|
||||||
.cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (priceEntry == null)
|
|
||||||
{
|
|
||||||
// Price is unknown
|
|
||||||
return ResponseEntity.notFound()
|
|
||||||
.cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemPrice itemPrice = new ItemPrice();
|
|
||||||
itemPrice.setId(itemId);
|
|
||||||
itemPrice.setName(priceEntry.getName());
|
|
||||||
itemPrice.setPrice(priceEntry.getPrice());
|
|
||||||
itemPrice.setTime(priceEntry.getTime());
|
|
||||||
|
|
||||||
return ResponseEntity.ok()
|
|
||||||
.cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic())
|
|
||||||
.body(itemPrice);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/price")
|
|
||||||
public ItemPrice[] prices(@RequestParam("id") int[] itemIds)
|
|
||||||
{
|
|
||||||
if (itemIds.length > MAX_BATCH_LOOKUP)
|
|
||||||
{
|
|
||||||
itemIds = Arrays.copyOf(itemIds, MAX_BATCH_LOOKUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PriceEntry> prices = itemService.getPrices(itemIds);
|
|
||||||
|
|
||||||
return prices.stream()
|
|
||||||
.map(priceEntry ->
|
|
||||||
{
|
|
||||||
ItemPrice itemPrice = new ItemPrice();
|
|
||||||
itemPrice.setId(priceEntry.getItem());
|
|
||||||
itemPrice.setName(priceEntry.getName());
|
|
||||||
itemPrice.setPrice(priceEntry.getPrice());
|
|
||||||
itemPrice.setTime(priceEntry.getTime());
|
|
||||||
return itemPrice;
|
|
||||||
})
|
|
||||||
.toArray(ItemPrice[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/prices")
|
@GetMapping("/prices")
|
||||||
public ResponseEntity<ItemPrice[]> prices()
|
public ResponseEntity<ItemPrice[]> prices()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,11 +31,9 @@ import java.io.InputStreamReader;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.cache.definitions.ItemDefinition;
|
import net.runelite.cache.definitions.ItemDefinition;
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
@@ -111,60 +109,6 @@ public class ItemService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PriceEntry getPrice(Connection con, int itemId, Instant time)
|
|
||||||
{
|
|
||||||
if (time != null)
|
|
||||||
{
|
|
||||||
return con.createQuery("select item, name, price, time, fetched_time from prices t1 join items t2 on t1.item=t2.id where item = :item and time <= :time order by time desc limit 1")
|
|
||||||
.addParameter("item", itemId)
|
|
||||||
.addParameter("time", time.toString())
|
|
||||||
.executeAndFetchFirst(PriceEntry.class);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return con.createQuery("select item, name, price, time, fetched_time from prices t1 join items t2 on t1.item=t2.id where item = :item order by time desc limit 1")
|
|
||||||
.addParameter("item", itemId)
|
|
||||||
.executeAndFetchFirst(PriceEntry.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public PriceEntry getPrice(int itemId, Instant time)
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
return getPrice(con, itemId, time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PriceEntry> getPrices(int... itemIds)
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
Set<Integer> seen = new HashSet<>();
|
|
||||||
List<PriceEntry> priceEntries = new ArrayList<>(itemIds.length);
|
|
||||||
|
|
||||||
for (int itemId : itemIds)
|
|
||||||
{
|
|
||||||
if (seen.contains(itemId))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
seen.add(itemId);
|
|
||||||
|
|
||||||
PriceEntry priceEntry = getPrice(con, itemId, null);
|
|
||||||
|
|
||||||
if (priceEntry == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
priceEntries.add(priceEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
return priceEntries;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemEntry fetchItem(int itemId)
|
public ItemEntry fetchItem(int itemId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user