Skip to content

Commit

Permalink
Merge pull request #460 from moreal/fewer-transactions-fetches
Browse files Browse the repository at this point in the history
Cache transactions request
  • Loading branch information
moreal authored Oct 29, 2024
2 parents 6a3a3ce + 81c4e9b commit 71a7cf3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Lib9c.GraphQL/Lib9c.GraphQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Lib9c" Version="1.19.0" />
<PackageReference Include="Libplanet" Version="5.3.0-alpha.3" />
<PackageReference Include="Libplanet" Version="5.3.2-alpha.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.Models.Tests/Lib9c.Models.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Lib9c" Version="1.19.0" />
<PackageReference Include="Libplanet" Version="5.3.0-alpha.3" />
<PackageReference Include="Libplanet" Version="5.3.2-alpha.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
Expand Down
2 changes: 1 addition & 1 deletion Lib9c.Models/Lib9c.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore" Version="13.9.12" />
<PackageReference Include="Lib9c" Version="1.19.0" />
<PackageReference Include="Libplanet" Version="5.3.0-alpha.3" />
<PackageReference Include="Libplanet" Version="5.3.2-alpha.1" />
<PackageReference Include="MongoDB.Driver" Version="2.27.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Mimir.MongoDB/Mimir.MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="HotChocolate.Abstractions" Version="13.9.12" />
<PackageReference Include="HotChocolate.Data.MongoDb" Version="13.9.12" />
<PackageReference Include="Lib9c" Version="1.19.0"/>
<PackageReference Include="Libplanet" Version="5.3.0-alpha.3" />
<PackageReference Include="Libplanet" Version="5.3.2-alpha.1" />
<PackageReference Include="MongoDB.Bson" Version="2.27.0" />
<PackageReference Include="MongoDB.Driver" Version="2.27.0" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.27.0" />
Expand Down
10 changes: 7 additions & 3 deletions Mimir.Worker/Client/HeadlessGQLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using BitFaster.Caching.Lru;
using Libplanet.Crypto;
using Microsoft.IdentityModel.Tokens;
using Serilog;
Expand All @@ -16,6 +17,7 @@ public class HeadlessGQLClient : IHeadlessGQLClient
private readonly Uri[] _urls;
private readonly string? _issuer;
private readonly string? _secret;
private readonly ConcurrentLru<long, GetTransactionsResponse> _transactionCache = new(10);
private const int RetryAttempts = 3;
private const int DelayInSeconds = 5;

Expand Down Expand Up @@ -207,10 +209,12 @@ public async Task<GetTransactionsResponse> GetTransactionsAsync(
CancellationToken stoppingToken = default
)
{
return await PostGraphQLRequestAsync<GetTransactionsResponse>(
return await _transactionCache.GetOrAddAsync(
blockIndex,
async (index) => await PostGraphQLRequestAsync<GetTransactionsResponse>(
GraphQLQueries.GetTransactions,
new { blockIndex, limit },
new { blockIndex=index, limit },
stoppingToken
);
));
}
}
5 changes: 3 additions & 2 deletions Mimir.Worker/Mimir.Worker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
<ItemGroup>
<PackageReference Include="Lib9c" Version="1.19.0" />
<PackageReference Include="Lib9c.Abstractions" Version="1.19.0" />
<PackageReference Include="Libplanet.RocksDBStore" Version="5.3.0-alpha.3" />
<PackageReference Include="Libplanet" Version="5.3.0-alpha.3" />
<PackageReference Include="Libplanet.RocksDBStore" Version="5.3.2-alpha.1" />
<PackageReference Include="Libplanet" Version="5.3.2-alpha.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Sentry" Version="4.12.1" />
<PackageReference Include="Sentry.Serilog" Version="4.12.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
<PackageReference Include="BitFaster.Caching" Version="2.5.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Mimir/Mimir.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Lib9c" Version="1.19.0" />
<PackageReference Include="Libplanet" Version="5.3.0-alpha.3" />
<PackageReference Include="Libplanet" Version="5.3.2-alpha.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.7" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.3.1" />
<PackageReference Include="Sentry" Version="4.12.1" />
Expand Down

0 comments on commit 71a7cf3

Please sign in to comment.