Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Output caching #105

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 190 additions & 71 deletions Tzkt.Api/Controllers/BigMapsController.cs

Large diffs are not rendered by default.

50 changes: 49 additions & 1 deletion Tzkt.Api/Parameters/AccountParameter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NJsonSchema.Annotations;
Expand All @@ -7,7 +9,7 @@ namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(AccountBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class AccountParameter
public class AccountParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -74,5 +76,51 @@ public class AccountParameter

[JsonIgnore]
public bool NiHasNull { get; set; }


public string Normalize(string name)
{
var sb = new StringBuilder();

if (Eq != null)
{
sb.Append($"{name}.eq={Eq}&");
}

if (Ne != null)
{
sb.Append($"{name}.ne={Ne}&");
}

if (In != null && In.Any())
{
sb.Append($"{name}.in={string.Join(",", In.OrderBy(x => x))}&");
}

if (Ni != null && Ni.Any())
{
sb.Append($"{name}.ni={string.Join(",", Ni.OrderBy(x => x))}&");
}

if (Eqx != null)
{
sb.Append($"{name}.eqx={Eqx}&");
}

if (Nex != null)
{
sb.Append($"{name}.nex={Nex}&");
}

if (Null != null)
{
sb.Append($"{name}.null={Null}&");
}

sb.Append($"{name}.NiHasNull={NiHasNull}&");
sb.Append($"{name}.InHasNull={InHasNull}&");

return sb.ToString();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/AccountTypeParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(AccountTypeBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
[JsonSchemaExtensionData("x-tzkt-query-parameter", "user,contract,delegate")]
public class AccountTypeParameter
public class AccountTypeParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand All @@ -25,5 +25,10 @@ public class AccountTypeParameter
/// </summary>
[JsonSchemaType(typeof(string))]
public int? Ne { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
6 changes: 5 additions & 1 deletion Tzkt.Api/Parameters/AnyOfParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(AnyOfBinder))]
[JsonSchemaType(typeof(string))]
[JsonSchemaExtensionData("x-tzkt-extension", "anyof-parameter")]
public class AnyOfParameter
public class AnyOfParameter : INormalizable
{
public IEnumerable<string> Fields { get; set; }

public int Value { get; set; }
public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/BakingRightStatusParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(BakingRightStatusBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
[JsonSchemaExtensionData("x-tzkt-query-parameter", "future,realized,uncovered,missed")]
public class BakingRightStatusParameter
public class BakingRightStatusParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand All @@ -25,5 +25,10 @@ public class BakingRightStatusParameter
/// </summary>
[JsonSchemaType(typeof(string))]
public int? Ne { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/BakingRightTypeParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(BakingRightTypeBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
[JsonSchemaExtensionData("x-tzkt-query-parameter", "baking,endorsing")]
public class BakingRightTypeParameter
public class BakingRightTypeParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand All @@ -25,5 +25,10 @@ public class BakingRightTypeParameter
/// </summary>
[JsonSchemaType(typeof(string))]
public int? Ne { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 7 additions & 0 deletions Tzkt.Api/Parameters/Base/INormalizable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Tzkt.Api
{
public interface INormalizable
{
public string Normalize(string name);
}
}
31 changes: 30 additions & 1 deletion Tzkt.Api/Parameters/BigMapActionParameter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Annotations;

Expand All @@ -7,7 +9,7 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(BigMapActionBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
[JsonSchemaExtensionData("x-tzkt-query-parameter", "allocate,add_key,update_key,remove_key,remove")]
public class BigMapActionParameter
public class BigMapActionParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -44,5 +46,32 @@ public class BigMapActionParameter
/// </summary>
[JsonSchemaType(typeof(List<string>))]
public List<int> Ni { get; set; }

public string Normalize(string name)
{
var sb = new StringBuilder();

if (Eq != null)
{
sb.Append($"{name}.eq={Eq}&");
}

if (Ne != null)
{
sb.Append($"{name}.ne={Ne}&");
}

if (In != null && In.Any())
{
sb.Append($"{name}.in={string.Join(",", In.OrderBy(x => x))}&");
}

if (Ni != null && Ni.Any())
{
sb.Append($"{name}.ni={string.Join(",", Ni.OrderBy(x => x))}&");
}

return sb.ToString();
}
}
}
25 changes: 24 additions & 1 deletion Tzkt.Api/Parameters/BigMapTagsParameter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Annotations;

Expand All @@ -7,7 +8,7 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(BigMapTagsBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
[JsonSchemaExtensionData("x-tzkt-query-parameter", "metadata,token_metadata,ledger")]
public class BigMapTagsParameter
public class BigMapTagsParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -36,5 +37,27 @@ public class BigMapTagsParameter
/// </summary>
[JsonSchemaType(typeof(List<string>))]
public int? All { get; set; }

public string Normalize(string name)
{
var sb = new StringBuilder();

if (Eq != null)
{
sb.Append($"{name}.eq={Eq}&");
}

if (Any != null)
{
sb.Append($"{name}.any={Any}&");
}

if (All != null)
{
sb.Append($"{name}.all={All}&");
}

return sb.ToString();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/BoolParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(BoolBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class BoolParameter
public class BoolParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=true` is the same as `param=true`). \
Expand All @@ -22,5 +22,10 @@ public class BoolParameter
/// Example: `?active.null` or `?active.null=false`.
/// </summary>
public bool? Null { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/ContractKindParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(ContractKindBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
[JsonSchemaExtensionData("x-tzkt-query-parameter", "delegator_contract,smart_contract")]
public class ContractKindParameter
public class ContractKindParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -44,5 +44,10 @@ public class ContractKindParameter
/// </summary>
[JsonSchemaType(typeof(List<string>))]
public List<int> Ni { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/ContractTagsParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Tzkt.Api
[ModelBinder(BinderType = typeof(ContractTagsBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
[JsonSchemaExtensionData("x-tzkt-query-parameter", "fa1,fa12,fa2")]
public class ContractTagsParameter
public class ContractTagsParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -36,5 +36,10 @@ public class ContractTagsParameter
/// </summary>
[JsonSchemaType(typeof(List<string>))]
public int? All { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/DateTimeParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(DateTimeBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class DateTimeParameter
public class DateTimeParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=2020-01-01` is the same as `param=2020-01-01`). \
Expand Down Expand Up @@ -72,5 +72,10 @@ public class DateTimeParameter
/// Example: `?timestamp.ni=2020-02-20,2020-02-21`.
/// </summary>
public List<DateTime> Ni { get; set; }

public string Normalize(string name)
{
throw new NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/ExpressionParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(ExpressionBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class ExpressionParameter
public class ExpressionParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -43,5 +43,10 @@ public class ExpressionParameter
#region operators
public static implicit operator ExpressionParameter(string value) => new() { Eq = value };
#endregion

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/Int32ExParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(Int32ExBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class Int32ExParameter
public class Int32ExParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -95,5 +95,10 @@ public class Int32ExParameter
/// Example: `?nonce.null` or `?nonce.null=false`.
/// </summary>
public bool? Null { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
7 changes: 6 additions & 1 deletion Tzkt.Api/Parameters/Int32NullParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tzkt.Api
{
[ModelBinder(BinderType = typeof(Int32NullBinder))]
[JsonSchemaExtensionData("x-tzkt-extension", "query-parameter")]
public class Int32NullParameter
public class Int32NullParameter : INormalizable
{
/// <summary>
/// **Equal** filter mode (optional, i.e. `param.eq=123` is the same as `param=123`). \
Expand Down Expand Up @@ -79,5 +79,10 @@ public class Int32NullParameter
/// Example: `?nonce.null` or `?nonce.null=false`.
/// </summary>
public bool? Null { get; set; }

public string Normalize(string name)
{
throw new System.NotImplementedException();
}
}
}
Loading