@@ -25,6 +25,8 @@ defmodule BlockchainAPI.Query.Stats do
25
25
26
26
def list ( ) do
27
27
Cache.Util . get ( :stats_cache , :stats , & set_list / 0 , @ cache_timeout )
28
+ # {:commit, data} = set_list()
29
+ # data
28
30
end
29
31
30
32
defp set_list ( ) do
@@ -184,15 +186,16 @@ defmodule BlockchainAPI.Query.Stats do
184
186
defp query_frequent_concensus_members ( start , finish ) do
185
187
count_query =
186
188
from (
187
- cm in ConsensusMember ,
188
- inner_join: et in ElectionTransaction ,
189
- on: et . id == cm . election_transactions_id ,
189
+ b in Block ,
190
190
inner_join: tx in Transaction ,
191
- on: tx . hash == et . hash ,
192
- inner_join: b in Block ,
193
191
on: b . height == tx . block_height ,
192
+ inner_join: et in ElectionTransaction ,
193
+ on: tx . hash == et . hash ,
194
+ inner_join: cm in ConsensusMember ,
195
+ on: et . id == cm . election_transactions_id ,
194
196
where: b . time >= ^ start ,
195
197
where: b . time <= ^ finish ,
198
+ where: tx . type == "election" ,
196
199
group_by: cm . address ,
197
200
select: % {
198
201
count: fragment ( "count(*)" ) ,
@@ -230,11 +233,12 @@ defmodule BlockchainAPI.Query.Stats do
230
233
defp query_top_grossing_hotspots ( start , finish ) do
231
234
sum_query =
232
235
from (
233
- rt in RewardTxn ,
236
+ b in Block ,
234
237
inner_join: tx in Transaction ,
235
- on: tx . hash == rt . rewards_hash ,
236
- inner_join: b in Block ,
237
238
on: b . height == tx . block_height ,
239
+ inner_join: rt in RewardTxn ,
240
+ on: tx . hash == rt . rewards_hash ,
241
+ where: tx . type == "rewards" ,
238
242
where: b . time >= ^ start ,
239
243
where: b . time <= ^ finish ,
240
244
where: not is_nil ( rt . gateway ) ,
@@ -276,16 +280,8 @@ defmodule BlockchainAPI.Query.Stats do
276
280
distance_query =
277
281
from (
278
282
pw in POCWitness ,
279
- inner_join: pe in POCPathElement ,
280
- on: pe . id == pw . poc_path_elements_id ,
281
- inner_join: rt in POCReceiptsTransaction ,
282
- on: rt . hash == pe . poc_receipts_transactions_hash ,
283
- inner_join: tx in Transaction ,
284
- on: tx . hash == rt . hash ,
285
- inner_join: b in Block ,
286
- on: b . height == tx . block_height ,
287
- where: b . time >= ^ start ,
288
- where: b . time <= ^ finish ,
283
+ where: pw . timestamp / 1000000000 >= ^ start ,
284
+ where: pw . timestamp / 1000000000 <= ^ finish ,
289
285
select: % {
290
286
gateway: pw . gateway ,
291
287
distance: pw . distance ,
@@ -327,4 +323,10 @@ defmodule BlockchainAPI.Query.Stats do
327
323
interval -> interval |> Decimal . to_float ( )
328
324
end
329
325
end
326
+
327
+ defp print_sql ( queryable ) do
328
+ { query , params } = Ecto.Adapters.SQL . to_sql ( :all , Repo , queryable )
329
+ IO . puts ( "#{ query } , #{ inspect ( params ) } " )
330
+ queryable
331
+ end
330
332
end
0 commit comments