Skip to content

Commit d29d29e

Browse files
authored
chore: precompute tx ids (#1239)
1 parent 50d8fc6 commit d29d29e

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

lib/ae_mdw/application.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ defmodule AeMdw.Application do
8989
{tx_field_types, put_in(tx_fields[type], fields), put_in(tx_ids[type], ids)}
9090
end)
9191

92+
tx_ids_values =
93+
Enum.into(tx_ids, %{}, fn {type, field_ids} ->
94+
{type, Map.values(field_ids)}
95+
end)
96+
9297
id_field_type_map =
9398
Enum.reduce(tx_ids, %{}, fn {type, ids_map}, acc ->
9499
for {field, pos} <- ids_map,
@@ -119,6 +124,7 @@ defmodule AeMdw.Application do
119124
tx_type: Util.inverse(type_name_map),
120125
tx_fields: tx_fields,
121126
tx_ids: tx_ids,
127+
tx_ids_values: tx_ids_values,
122128
id_prefix: id_prefix_type_map,
123129
id_field_type: id_field_type_map |> Enum.concat([{[:_], nil}]),
124130
id_fields: [{[], MapSet.new(id_fields)}],

lib/ae_mdw/db/mutations/int_calls_mutation.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ defmodule AeMdw.Db.IntCallsMutation do
6565
|> State.put(Model.FnameGrpIntContractCall, m_fname_grp_call)
6666

6767
tx_type
68-
|> Node.tx_ids()
69-
|> Enum.reduce(state2, fn {_field, pos}, state ->
70-
pk = Validate.id!(elem(tx, pos))
71-
m_id_call = Model.id_int_contract_call(index: {pk, pos, call_txi, local_idx})
68+
|> Node.tx_ids_values()
69+
|> Enum.reduce(state2, fn field_pos, state ->
70+
pk = Validate.id!(elem(tx, field_pos))
71+
m_id_call = Model.id_int_contract_call(index: {pk, field_pos, call_txi, local_idx})
7272

7373
m_grp_id_call =
74-
Model.grp_id_int_contract_call(index: {create_txi, pk, pos, call_txi, local_idx})
74+
Model.grp_id_int_contract_call(index: {create_txi, pk, field_pos, call_txi, local_idx})
7575

7676
m_id_fname_call =
77-
Model.id_fname_int_contract_call(index: {pk, fname, pos, call_txi, local_idx})
77+
Model.id_fname_int_contract_call(index: {pk, fname, field_pos, call_txi, local_idx})
7878

7979
m_grp_id_fname_call =
8080
Model.grp_id_fname_int_contract_call(
81-
index: {create_txi, pk, fname, pos, call_txi, local_idx}
81+
index: {create_txi, pk, fname, field_pos, call_txi, local_idx}
8282
)
8383

8484
state

lib/ae_mdw/fields.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ defmodule AeMdw.Fields do
6262
|> Enum.flat_map(fn tx_type ->
6363
types_pos =
6464
tx_type
65-
|> Node.tx_ids()
66-
|> Enum.map(fn {_field, pos} -> {tx_type, pos} end)
65+
|> Node.tx_ids_values()
66+
|> Enum.map(fn field_pos -> {tx_type, field_pos} end)
6767

6868
if tx_type in @create_tx_types do
6969
[{tx_type, nil} | types_pos]

lib/ae_mdw/node.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ defmodule AeMdw.Node do
195195
%{}
196196
end
197197

198+
@spec tx_ids_values(atom()) :: [non_neg_integer()]
199+
def tx_ids_values(_tx_type) do
200+
[]
201+
end
202+
198203
@spec tx_mod(module()) :: module()
199204
def tx_mod(_arg) do
200205
:foo

lib/ae_mdw/txs.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ defmodule AeMdw.Txs do
374374
end
375375

376376
Enum.flat_map(tx_types, fn tx_type ->
377-
poss = tx_type |> Node.tx_ids() |> Map.values() |> Enum.map(&{tx_type, &1})
377+
poss = tx_type |> Node.tx_ids_values() |> Enum.map(&{tx_type, &1})
378378
# nil - for link
379379
poss = if tx_type in @create_tx_types, do: [{tx_type, nil} | poss], else: poss
380380

@@ -544,9 +544,9 @@ defmodule AeMdw.Txs do
544544

545545
defp field_count(state, tx_type, address) do
546546
tx_type
547-
|> Node.tx_ids()
548-
|> Enum.map(fn {_field, pos} ->
549-
case State.get(state, Model.IdCount, {tx_type, pos, address}) do
547+
|> Node.tx_ids_values()
548+
|> Enum.map(fn field_pos ->
549+
case State.get(state, Model.IdCount, {tx_type, field_pos, address}) do
550550
{:ok, Model.id_count(count: count)} -> count
551551
:not_found -> 0
552552
end

lib/ae_mdw_web/websocket/broadcaster.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,8 @@ defmodule AeMdwWeb.Websocket.Broadcaster do
264264
{tx_type, naked_tx} = :aetx.specialize_type(wrapped_tx)
265265

266266
tx_type
267-
|> AeMdw.Node.tx_ids()
268-
|> Map.values()
267+
|> AeMdw.Node.tx_ids_values()
269268
|> Enum.map(&elem(naked_tx, &1))
270-
|> Enum.map(&AeMdw.Validate.id!/1)
271269
|> Enum.uniq()
272270
end
273271

0 commit comments

Comments
 (0)