Skip to content

Commit 8c24671

Browse files
committed
DUP: use a more elegant style when handling some queries
Some relevant comments were left after a merged PR. Implement them. Signed-off-by: Arnaldo Cesco <arnaldo.cesco@secomind.com>
1 parent b681b39 commit 8c24671

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/data_updater/impl.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Impl do
501501
:ok <- can_write_on_interface?(interface_descriptor),
502502
interface_id <- interface_descriptor.interface_id,
503503
{:ok, mapping} <- resolve_path(path, interface_descriptor, new_state.mappings),
504-
endpoint_id <- mapping.endpoint_id,
504+
endpoint_id = mapping.endpoint_id,
505505
db_retention_policy = mapping.database_retention_policy,
506506
db_ttl = mapping.database_retention_ttl,
507507
{value, value_timestamp, _metadata} <-

apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/data_updater/queries.ex

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Queries do
7373
update: [set: [pending_empty_cache: ^pending_empty_cache]]
7474

7575
case Repo.safe_update_all(device, []) do
76-
{1, _} ->
76+
{:ok, _} ->
7777
:ok
7878

7979
{:error, reason} ->
@@ -587,7 +587,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Queries do
587587
update: [set: [old_introspection: fragment(" old_introspection + ?", ^old_interfaces)]]
588588

589589
case Repo.safe_update_all(device, [], consistency: :quorum) do
590-
{1, _} ->
590+
{:ok, _} ->
591591
:ok
592592

593593
{:error, reason} ->
@@ -616,7 +616,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Queries do
616616
update: [set: [old_introspection: fragment(" old_introspection - ?", ^old_interfaces)]]
617617

618618
case Repo.safe_update_all(device, [], consistency: :quorum) do
619-
{1, _} ->
619+
{:ok, _} ->
620620
:ok
621621

622622
{:error, reason} ->
@@ -678,14 +678,12 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Queries do
678678
encoded_device_id = CoreDevice.encode_device_id(device_id)
679679

680680
query =
681-
from(
682-
KvStore
683-
|> where(group: ^group, key: ^encoded_device_id)
684-
|> put_query_prefix(keyspace_name)
685-
)
681+
from(KvStore)
682+
|> where(group: ^group, key: ^encoded_device_id)
683+
|> put_query_prefix(keyspace_name)
686684

687685
case Repo.safe_delete_all(query, consistency: :each_quorum) do
688-
{n, _} when is_integer(n) ->
686+
{:ok, _} ->
689687
:ok
690688

691689
{:error, reason} ->

apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/repo.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ defmodule Astarte.DataUpdaterPlant.Repo do
5050

5151
def safe_update_all(queryable, updates, opts \\ []) do
5252
try do
53-
update_all(queryable, updates, opts)
53+
{:ok, update_all(queryable, updates, opts)}
5454
catch
5555
error ->
5656
handle_xandra_error(error)
@@ -59,7 +59,7 @@ defmodule Astarte.DataUpdaterPlant.Repo do
5959

6060
def safe_delete_all(queryable, opts \\ []) do
6161
try do
62-
delete_all(queryable, opts)
62+
{:ok, delete_all(queryable, opts)}
6363
catch
6464
error ->
6565
handle_xandra_error(error)

0 commit comments

Comments
 (0)