From bdcd096c09864424103e559c737032a736783388 Mon Sep 17 00:00:00 2001 From: Osman Hadzic Date: Thu, 28 Nov 2024 13:52:12 +0100 Subject: [PATCH] Refactor: streamline state handling in populatedb State is now updated using the `%Import.State{}` struct, modifying the data field to include the new `last_seen_reception_timestamp` value. Signed-off-by: Osman Hadzic --- .../lib/astarte/import/populatedb.ex | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/astarte_import/lib/astarte/import/populatedb.ex b/tools/astarte_import/lib/astarte/import/populatedb.ex index 0502670d1..215c91315 100644 --- a/tools/astarte_import/lib/astarte/import/populatedb.ex +++ b/tools/astarte_import/lib/astarte/import/populatedb.ex @@ -330,15 +330,17 @@ defmodule Astarte.Import.PopulateDB do got_end_of_object_fun = fn state, object -> %Import.State{ reception_timestamp: reception_timestamp, - data: %State{ - mappings: mappings, - prepared_params: prepared_params, - prepared_query: prepared_query, - value_columns: value_columns, - value_type: expected_types - } + data: data } = state + %State{ + mappings: mappings, + prepared_params: prepared_params, + prepared_query: prepared_query, + value_columns: value_columns, + value_type: expected_types + } = data + reception_submillis = rem(DateTime.to_unix(reception_timestamp, :microsecond), 100) {:ok, native_value} = to_native_type(object, expected_types) @@ -360,7 +362,10 @@ defmodule Astarte.Import.PopulateDB do {:ok, %Xandra.Void{}} = Xandra.execute(xandra_conn, prepared_query, params) - state + %Import.State{ + state + | data: %State{data | last_seen_reception_timestamp: reception_timestamp} + } end got_end_of_property_fun = fn state, chars ->