Skip to content

Commit

Permalink
fix(ip): cache ip queries (#907)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
NathanFlurry committed Jun 16, 2024
1 parent 93e705c commit c36d150
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion svc/pkg/ip/ops/info/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,25 @@ async fn handle(ctx: OperationContext<ip::info::Request>) -> GlobalResult<ip::in

// Fetch info
let ip_info = match provider {
ip::info::Provider::IpInfoIo => fetch_ip_info_io(&ctx, ctx.ts(), &ip_str).await?,
ip::info::Provider::IpInfoIo => {
ctx.cache()
.fetch_one_proto("ipinfo.ip", ip_str, {
let ctx = ctx.clone();
move |mut cache, ip_str| {
let ctx = ctx.clone();
async move {
let ip_info = fetch_ip_info_io(&ctx, ctx.ts(), &ip_str).await?;
if let Some(ip_info) = ip_info {
cache.resolve(&ip_str, ip_info);
} else {
// TODO(RVT-3792): Cache miss will hit database all of the time
}
Ok(cache)
}
}
})
.await?
}
};

Ok(ip::info::Response { ip_info })
Expand Down

0 comments on commit c36d150

Please sign in to comment.