[fix 4387] query mailserver in batches of 24 hours

This commit is contained in:
Eric Dvorsak 2018-05-28 14:53:26 +02:00 committed by Roman Volosovskyi
parent d8c8608419
commit ee7895fe43
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 41 additions and 27 deletions

View File

@ -97,21 +97,31 @@
(success-fn resp) (success-fn resp)
(error-fn err))))) (error-fn err)))))
(def one-day (* 24 3600))
(def seven-days (* 7 one-day))
(defn request-inbox-messages (defn request-inbox-messages
[web3 wnode topics to from sym-key-id success-fn error-fn] [web3 wnode topics from to sym-key-id success-fn error-fn]
(let [opts (merge {:mailServerPeer wnode (loop [from from
:symKeyID sym-key-id} current-to to]
(when from {:from from}) (let [current-to (if (> (- to from) one-day)
(when to {:to to}))] (+ from one-day)
(log/info "offline inbox: request-messages request for topics " topics) to)
(doseq [topic topics] opts (merge {:mailServerPeer wnode
(let [opts (assoc opts :topic topic)] :symKeyID sym-key-id
(.requestMessages (transport.utils/shh web3) :from from
(clj->js opts) :to current-to})]
(fn [err resp] (log/info "offline inbox: request-messages request for topics " topics " from " from " to " current-to)
(if-not err (doseq [topic topics]
(success-fn resp) (let [opts (assoc opts :topic topic)]
(error-fn err topic)))))))) (.requestMessages (transport.utils/shh web3)
(clj->js opts)
(fn [err resp]
(if-not err
(success-fn resp topic)
(error-fn err topic))))))
(when (< current-to to)
(recur current-to to)))))
(re-frame/reg-fx (re-frame/reg-fx
::add-peer ::add-peer
@ -134,23 +144,25 @@
(request-inbox-messages web3 (request-inbox-messages web3
wnode wnode
topics topics
to
from from
to
sym-key-id sym-key-id
#(log/info "offline inbox: request-messages response" %) #(log/info "offline inbox: request-messages response" %1 %2 from to)
#(log/error "offline inbox: request-messages error" %1 %2 to from)))) #(log/error "offline inbox: request-messages error" %1 %2 from to))))
(re-frame/reg-fx (re-frame/reg-fx
::request-history ::request-history
(fn [{:keys [wnode topics to from sym-key-id web3]}] (fn [{:keys [wnode topics now-in-s sym-key-id web3]}]
(request-inbox-messages web3 (let [from (- now-in-s seven-days)
wnode to now-in-s]
topics (request-inbox-messages web3
to wnode
from topics
sym-key-id from
#(log/info "offline inbox: request-messages response" %) to
#(log/error "offline inbox: request-messages error" %1 %2 to from)))) sym-key-id
#(log/info "offline inbox: request-messages response" %1 %2 from to)
#(log/error "offline inbox: request-messages error" %1 %2 from to)))))
(defn update-mailserver-status [transition {:keys [db]}] (defn update-mailserver-status [transition {:keys [db]}]
(let [state transition] (let [state transition]
@ -246,7 +258,7 @@
sym-key-id (:inbox/sym-key-id db) sym-key-id (:inbox/sym-key-id db)
now-in-s (quot now 1000) now-in-s (quot now 1000)
last-request (get-in db [:account/account :last-request] last-request (get-in db [:account/account :last-request]
(- now-in-s (* 3600 24))) (- now-in-s seven-days))
request-messages-topics (get-request-messages-topics db) request-messages-topics (get-request-messages-topics db)
request-history-topics (get-request-history-topics db)] request-history-topics (get-request-history-topics db)]
(when (inbox-ready? cofx) (when (inbox-ready? cofx)
@ -257,6 +269,7 @@
:sym-key-id sym-key-id :sym-key-id sym-key-id
:web3 web3} :web3 web3}
::request-history {:wnode wnode ::request-history {:wnode wnode
:now-in-s now-in-s
:topics request-history-topics :topics request-history-topics
:sym-key-id sym-key-id :sym-key-id sym-key-id
:web3 web3} :web3 web3}
@ -276,6 +289,7 @@
(when (inbox-ready? cofx) (when (inbox-ready? cofx)
{::request-history {:wnode wnode {::request-history {:wnode wnode
:topics [topic] :topics [topic]
:now-in-s now-in-s
:sym-key-id sym-key-id :sym-key-id sym-key-id
:web3 web3} :web3 web3}
:db (assoc db :inbox/fetching? true) :db (assoc db :inbox/fetching? true)