From 139c24949793ae0c9fe25fb69d52087f4bd73f12 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Sat, 30 Nov 2024 23:22:17 -0500 Subject: [PATCH] Reduce max_bytes_request_body --- .gitignore | 1 + build.zig | 4 ++-- src/app/jobs/process_scrobbles.zig | 11 ++++++++++- src/main.zig | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a485595..abb3b4e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ static/ .jetzig src/app/database/data.db-journal src/app/database/old_migrations/ +src/lib/ diff --git a/build.zig b/build.zig index 95a299d..4ceba31 100644 --- a/build.zig +++ b/build.zig @@ -29,7 +29,7 @@ pub fn build(b: *std.Build) !void { run_step.dependOn(&run_cmd.step); const lib_unit_tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -37,7 +37,7 @@ pub fn build(b: *std.Build) !void { const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); const exe_unit_tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); diff --git a/src/app/jobs/process_scrobbles.zig b/src/app/jobs/process_scrobbles.zig index 8cc1716..e0d276a 100644 --- a/src/app/jobs/process_scrobbles.zig +++ b/src/app/jobs/process_scrobbles.zig @@ -1,6 +1,9 @@ const std = @import("std"); const jetzig = @import("jetzig"); const jetquery = @import("jetzig").jetquery; +//const time = @cImport({ +// @cInclude("time.h"); +//}); // The `run` function for a job is invoked every time the job is processed by a queue worker // (or by the Jetzig server if the job is processed in-line). @@ -15,6 +18,8 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig _ = allocator; _ = params; + //const memory = try allocator.alloc(u8, 19); + // Get all scrobbles from the RawScrobbles table const query = jetzig.database.Query(.RawScrobble).select(.{}); @@ -22,6 +27,10 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig defer env.repo.free(scrobbles); for (scrobbles) |scrobble| { + //const date = [19]u8{}; + //time.strftime{ date, 19, "%Y-%m-%d %H:%M:%D", scrobbles.date }; + //time.strftime(memory, 19, "%Y-%m-%d %H:%M:%S", scrobbles.date); + //std.debug.print("{s}", .{memory}); // Make hashes const album_hash = std.hash.Fnv1a_64.hash(scrobble.album); @@ -70,7 +79,7 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig if (song_check == 0) try env.repo.execute(song_insert); const scrobble_offset = try jetzig.database.Query(.Scrobble).select(.{}).count().execute(env.repo) orelse unreachable; - try jetzig.database.Query(.Scrobble).insert(.{ .id = scrobble_offset + 1, .song_id = song_id, .album_id = album_id, .artist_id = artist_id }).execute(env.repo); + try jetzig.database.Query(.Scrobble).insert(.{ .id = scrobble_offset + 1, .song_id = song_id, .album_id = album_id, .artist_id = artist_id, .date = scrobble.date }).execute(env.repo); } // Clear RawScrobbles when done processing try jetzig.database.Query(.RawScrobble).deleteAll().execute(env.repo); diff --git a/src/main.zig b/src/main.zig index 7437920..73770eb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -19,7 +19,7 @@ pub const jetzig_options = struct { }; // Maximum bytes to allow in request body. - pub const max_bytes_request_body: usize = std.math.pow(usize, 2, 32); + pub const max_bytes_request_body: usize = std.math.pow(usize, 2, 24); // Maximum filesize for `public/` content. // pub const max_bytes_public_content: usize = std.math.pow(usize, 2, 20);