use nil as a default value for transaction cache

pull/1671/head
Ayrat Badykov 6 years ago
parent 979bf64807
commit 1d38f507ba
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 2
      apps/explorer/lib/explorer/chain.ex
  2. 2
      apps/explorer/lib/explorer/chain/transaction_count_cache.ex
  3. 2
      apps/explorer/test/explorer/chain/transaction_count_cache_test.exs

@ -1871,7 +1871,7 @@ defmodule Explorer.Chain do
def transaction_estimated_count do def transaction_estimated_count do
cached_value = TransactionCountCache.value() cached_value = TransactionCountCache.value()
if cached_value == 0 do if is_nil(cached_value) do
%Postgrex.Result{rows: [[rows]]} = %Postgrex.Result{rows: [[rows]]} =
SQL.query!(Repo, "SELECT reltuples::BIGINT AS estimate FROM pg_class WHERE relname='transactions'") SQL.query!(Repo, "SELECT reltuples::BIGINT AS estimate FROM pg_class WHERE relname='transactions'")

@ -12,7 +12,7 @@ defmodule Explorer.Chain.TransactionCountCache do
# 2 hours # 2 hours
@cache_period 1_000 * 60 * 60 * 2 @cache_period 1_000 * 60 * 60 * 2
@default_value 0 @default_value nil
@key "count" @key "count"
@name __MODULE__ @name __MODULE__

@ -8,7 +8,7 @@ defmodule Explorer.Chain.TransactionCountCacheTest do
result = TransactionCountCache.value(TestCache) result = TransactionCountCache.value(TestCache)
assert result == 0 assert is_nil(result)
end end
test "updates cache if initial value is zero" do test "updates cache if initial value is zero" do

Loading…
Cancel
Save