Commit 0c31facc authored by Cédric F.'s avatar Cédric F.

Purge cache only when needed

parent 002cd1df
......@@ -17,4 +17,10 @@ clean:
nginx:
sudo -u http -- nginx -c nginx/nginx.conf -p . -g 'daemon off;'
.PHONY: clean nginx
cache_buster:
sudo ./cache_buster.sh
dcrd:
./dcrd --rpcuser bitcoin --rpcpass secret
.PHONY: clean nginx cache_buster dcrd
#!/bin/bash -eu
test $UID -eq 0
LOG="/home/infertux/.dcrd/logs/mainnet/dcrd.log"
CACHE="$(dirname $0)/nginx/cache/rpc"
find "$CACHE" -mindepth 1 -delete -print
tail -F -n 0 "$LOG" | \
while read -r line; do
if echo "$line" | grep -E 'BMGR: Processed [0-9]+ blocks? in the last'; then
find "$CACHE" -mindepth 1 -delete -print
fi
done
......@@ -18,7 +18,7 @@ http {
include /etc/nginx/mime.types;
proxy_cache_path nginx/cache/rpc levels=1:2 keys_zone=rpc:100m max_size=10g inactive=1y use_temp_path=off;
proxy_cache_path nginx/cache/rpc levels=1 keys_zone=rpc:100m max_size=10g inactive=1y use_temp_path=off;
limit_req_zone $binary_remote_addr zone=default:10m rate=5r/s;
......@@ -86,7 +86,7 @@ http {
proxy_cache rpc;
proxy_cache_key $proxy_host#$request_body;
proxy_cache_methods GET HEAD POST;
proxy_cache_valid any 60s;
proxy_cache_valid any 1y; # purged by external process
proxy_cache_use_stale error timeout;
# proxy_cache_bypass $http_pragma; # set Pragma:no-cache to bypass cache
......@@ -97,19 +97,16 @@ http {
# proxy_pass http://localhost:8332/; # bitcoind
}
location /ws {
#proxy_ssl_ciphers HIGH:!aNULL:!MD5;
#proxy_ssl_session_reuse on;
proxy_http_version 1.1;
# proxy_read_timeout 86400;
location = /ws {
proxy_set_header Authorization "Basic Yml0Y29pbjpzZWNyZXQ="; # bitcoin:secret
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass https://localhost:9109/ws;
proxy_ssl_session_reuse on; # reduce CPU load by not doing a full TLS handshake for each request
proxy_http_version 1.1; # recommended for keepalive
proxy_pass https://localhost:9109/ws; # dcrd
}
location / {
......
......@@ -77,6 +77,16 @@ view model now =
]
]
header =
tr []
[ th [] [ text "hash" ]
, th [ class "d-none d-sm-block" ] [ text "type" ]
, th [] [ text "received" ]
, th [ class "d-none d-sm-block" ] [ text "time" ]
, th []
[ abbr [ title "confirmations" ] [ text "conf." ] ]
]
transactions model =
model.transactions
|> List.map
......@@ -87,7 +97,7 @@ view model now =
, td []
[ Transaction.sentToAddress model.address tx |> formatAmount ]
, td [ class "d-none d-sm-block" ] [ Transaction.formatTime tx now ]
, td [] [ text <| toString tx.confirmations ]
, td [] [ text <| formatNumber tx.confirmations ]
]
)
in
......@@ -100,7 +110,7 @@ view model now =
, dcrDataLink <| "address/" ++ model.address
]
, div [ class "card-body" ]
[ p [ class "card-text" ] (details model)
[ p [ class "card-text" ] <| details model
, hr [] []
, div [ class "row" ]
[ div [ class "col" ]
......@@ -112,16 +122,7 @@ view model now =
]
]
, table [ class "table table-dark table-striped" ]
[ thead []
[ tr []
[ th [] [ text "hash" ]
, th [ class "d-none d-sm-block" ] [ text "type" ]
, th [] [ text "received" ]
, th [ class "d-none d-sm-block" ] [ text "time" ]
, th []
[ abbr [ title "confirmations" ] [ text "conf." ] ]
]
]
[ thead [] [ header ]
, tbody [] <| transactions model
]
]
......
......@@ -358,7 +358,7 @@ decodeAmountIn =
Decode.float
|> Decode.andThen
(\float ->
if float > 0 then
if float >= 0 then
Decode.succeed float
else if float == -1.0e-8 then
--- XXX: unconfirmed txs will return -1 atom as placeholder
......
......@@ -9,6 +9,7 @@ module Trappisto.Helpers exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Regex
import Lib.HtmlAttributesExtra as HtmlAttributesExtra
......@@ -31,23 +32,26 @@ formatAmount float =
-- remove any floating point arithmetic errors
float * 1.0e8 |> round |> toFloat |> (flip (/)) 1.0e8
in
span [ class "amount" ]
[ text <| toString rounded ]
span [ class "amount" ] [ text <| formatNumber rounded ]
formatNumber : Int -> String
formatNumber int =
formatNumber : number -> String
formatNumber number =
let
split digits =
if String.length digits > 3 then
digits
|> String.dropRight 3
|> split
|> (::) (String.right 3 digits)
string =
toString number
regex =
if String.contains "." string then
"(\\d)(?=(\\d{3})+(?!\\d)\\.)"
else
[ digits ]
"(\\d)(?=(\\d{3})+(?!\\d))"
in
toString int |> split |> List.reverse |> String.join ","
Regex.replace
Regex.All
(Regex.regex regex)
(\{ match } -> match ++ ",")
string
shortAddress : String -> String
......
......@@ -122,11 +122,7 @@ update action model =
cmd =
if WebSocket.isMethod [ "blockconnected", "blockdisconnected" ] message then
Cmd.batch
[ getBestBlock updatedModel
, update (Query updatedModel.query) updatedModel
|> Tuple.second
]
getBestBlock updatedModel
else
Cmd.none
in
......@@ -192,14 +188,16 @@ update action model =
GetBestBlockResult result ->
case result of
Ok bestBlock ->
( { model
| lastBlockHash = bestBlock.hash
, lastBlockHeight = bestBlock.height
, fetching = False
, error = Nothing
}
, Cmd.none
)
let
updatedModel =
{ model
| lastBlockHash = bestBlock.hash
, lastBlockHeight = bestBlock.height
, fetching = False
, error = Nothing
}
in
update (Query updatedModel.query) updatedModel
Err error ->
( { model
......@@ -226,15 +224,6 @@ update action model =
let
( updatedModel, cmd ) =
BlockComponent.update blockMsg model.blockModel
-- query =
-- case blockMsg of
-- BlockComponent.GetBlock foo ->
-- updatedModel.hash
-- BlockComponent.GetBlockHash foo ->
-- toString updatedModel.height
-- _ ->
-- model.query
in
( { model
| template = Block
......
......@@ -127,7 +127,10 @@ statusView model =
if model.lastBlockHeight < 0 then
span [] [ text "??????" ]
else
queryLink model.lastBlockHash (toString model.lastBlockHeight) []
queryLink
model.lastBlockHash
(formatNumber model.lastBlockHeight)
[]
( wsClass, wsStatus ) =
if model.webSocketConnected then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment