|
@@ -1,41 +1,93 @@
|
|
|
-using AkazawaYun.PRO7;
|
|
|
+#pragma warning disable IDE1006,IL2026
|
|
|
+
|
|
|
+using AkazawaYun.AOT;
|
|
|
+using AkazawaYun.PRO7;
|
|
|
+using AkazawaYun.PRO7.AkazawaYunWebFunctionAOP;
|
|
|
using AkazawaYun.PRO7.AkazawaYunWebInterceptor;
|
|
|
-using System.Text.Json.Serialization;
|
|
|
+using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
namespace AkazawaYun.FrameworkBenchmarks;
|
|
|
|
|
|
-public class Program : IPostFunction
|
|
|
+class Program : IPostFunctionWrapper
|
|
|
{
|
|
|
- static async Task Main()
|
|
|
+ static readonly akzWebBuilder builder;
|
|
|
+ static readonly akzDbFactory mysql;
|
|
|
+
|
|
|
+
|
|
|
+ static Program()
|
|
|
{
|
|
|
- akzJson.Config(null, Json.Default);
|
|
|
- var server = await akzWebBuilder.Shared.Load().SetDefault().Build()
|
|
|
+ akzJson.Config(null, AotJsonContext.Default);
|
|
|
+ builder = akzWebBuilder.Shared.SetDefault()
|
|
|
+ .Build()
|
|
|
.Config<IWebReceptor, akzWebInterceptor>(itc =>
|
|
|
{
|
|
|
+ itc.ClearInterceptor();
|
|
|
itc.AddInterceptor(new akzWebInterceptorNotOnlyPost());
|
|
|
- }).Launch();
|
|
|
+ });
|
|
|
+ mysql = new akzDbBuilderII()
|
|
|
+ .SetServer("tfb-database:3306")
|
|
|
+ //.SetServer("localhost:3306")
|
|
|
+ .SetUser("benchmarkdbuser")
|
|
|
+ .SetPwd("benchmarkdbpass")
|
|
|
+ .SetDatabase("hello_world")
|
|
|
+ .SetCharset()
|
|
|
+ .SetOtherset()
|
|
|
+ .Build<Mysql>();
|
|
|
+ }
|
|
|
+ static async Task Main()
|
|
|
+ {
|
|
|
+ await builder.Launch();
|
|
|
akzLog.Default = akzLog.Output.None;
|
|
|
await Task.Delay(-1);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static ValueTask<HttpRes> plaintext(HttpReq _)
|
|
|
+ public static HttpRes plaintext() => HttpRes.HttpOK("Hello, World!", ".txt");
|
|
|
+ public static JsonModel json() => new()
|
|
|
+ {
|
|
|
+ message = "Hello, World!"
|
|
|
+ };
|
|
|
+
|
|
|
+ //[WebFunctionAopTry]
|
|
|
+ public static async Task<world> db()
|
|
|
{
|
|
|
- return HttpRes.HttpOK("Hello, World!", ".txt");
|
|
|
+ await using IDb con = await mysql.Connect();
|
|
|
+ world obj = await WorldService.GetRandomWorld(con);
|
|
|
+ return obj;
|
|
|
}
|
|
|
- public static ValueTask<HttpRes> json(HttpReq _)
|
|
|
+ //[WebFunctionAopTry]
|
|
|
+ public static async Task<world[]> queries(string queries)
|
|
|
{
|
|
|
- return HttpRes.HttpJson(new JsonResponse
|
|
|
- {
|
|
|
- message = "Hello, World!"
|
|
|
- });
|
|
|
+ int count = ParseCount(queries);
|
|
|
+
|
|
|
+ await using IDb con = await mysql.Connect();
|
|
|
+ world[] lst = await WorldService.GetWorlds(con, count);
|
|
|
+ return lst;
|
|
|
}
|
|
|
-}
|
|
|
+ //[WebFunctionAopTry]
|
|
|
+ public static async Task<world[]> updates(string queries)
|
|
|
+ {
|
|
|
+ int count = ParseCount(queries);
|
|
|
|
|
|
-public class JsonResponse
|
|
|
-{
|
|
|
- public string? message { get; set; }
|
|
|
-}
|
|
|
+ await using IDb con = await mysql.Connect();
|
|
|
+ world[] lst = await WorldService.GetWorlds(con, count);
|
|
|
+
|
|
|
+ foreach (world obj in lst)
|
|
|
+ obj.randomNumber = Random.Shared.Next(1, 10001);
|
|
|
+
|
|
|
+ await WorldService.SaveWorlds(con, lst);
|
|
|
+
|
|
|
+ return lst;
|
|
|
+ }
|
|
|
|
|
|
-[JsonSerializable(typeof(JsonResponse))]
|
|
|
-public partial class Json : JsonSerializerContext { }
|
|
|
+
|
|
|
+ static int ParseCount(string queries)
|
|
|
+ {
|
|
|
+ if (!int.TryParse(queries, out int count))
|
|
|
+ return 1;
|
|
|
+
|
|
|
+ count = Math.Clamp(count, 1, 500);
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|