Don't specify `to` when making the request to mailserver.
In some cases (say the clock of the device has drifted) specifying a `to` parameter is decrimental and might result in missing messages. We have changed the mailservers to default `to` if not present to `now`, which should gives us better guarantees. We also removed the 24 hours limit as now all the requests will be paginated according to the `limit` parameter. Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
cb4dc876f1
commit
dc0d42ee6b
|
@ -283,18 +283,14 @@
|
||||||
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from] :as request}]
|
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from] :as request}]
|
||||||
;; Add some room to from, unless we break day boundaries so that messages that have
|
;; Add some room to from, unless we break day boundaries so that messages that have
|
||||||
;; been received after the last request are also fetched
|
;; been received after the last request are also fetched
|
||||||
(let [adjusted-from (adjust-request-for-transit-time from)
|
(let [actual-from (adjust-request-for-transit-time from)
|
||||||
actual-limit (or (:limit request)
|
actual-limit (or (:limit request)
|
||||||
@limit)
|
@limit)]
|
||||||
actual-from (if (> (- to adjusted-from) one-day)
|
|
||||||
from
|
|
||||||
adjusted-from)]
|
|
||||||
(log/info "mailserver: request-messages for: "
|
(log/info "mailserver: request-messages for: "
|
||||||
" topics " topics
|
" topics " topics
|
||||||
" from " actual-from
|
" from " actual-from
|
||||||
" cursor " cursor
|
" cursor " cursor
|
||||||
" limit " actual-limit
|
" limit " actual-limit)
|
||||||
" to " to)
|
|
||||||
(.requestMessages (transport.utils/shh web3)
|
(.requestMessages (transport.utils/shh web3)
|
||||||
(clj->js {:topics topics
|
(clj->js {:topics topics
|
||||||
:mailServerPeer address
|
:mailServerPeer address
|
||||||
|
@ -302,8 +298,7 @@
|
||||||
:timeout request-timeout
|
:timeout request-timeout
|
||||||
:limit actual-limit
|
:limit actual-limit
|
||||||
:cursor cursor
|
:cursor cursor
|
||||||
:from actual-from
|
:from actual-from})
|
||||||
:to to})
|
|
||||||
(fn [error request-id]
|
(fn [error request-id]
|
||||||
(if-not error
|
(if-not error
|
||||||
(do
|
(do
|
||||||
|
@ -328,32 +323,25 @@
|
||||||
sym-key-id)
|
sym-key-id)
|
||||||
mailserver)))
|
mailserver)))
|
||||||
|
|
||||||
(defn split-request-per-day
|
(defn ->request
|
||||||
"NOTE: currently the mailserver is only accepting requests for a span
|
|
||||||
of 24 hours, so we split requests per 24h spans if the last request was
|
|
||||||
done more than 24h ago"
|
|
||||||
[now-in-s [last-request topics]]
|
[now-in-s [last-request topics]]
|
||||||
(let [days (conj
|
(when (< last-request now-in-s)
|
||||||
(into [] (range (max last-request
|
|
||||||
(- now-in-s one-day))
|
|
||||||
now-in-s
|
|
||||||
one-day))
|
|
||||||
now-in-s)
|
|
||||||
day-ranges (map vector days (rest days))]
|
|
||||||
(for [[from to] day-ranges]
|
|
||||||
{:topics topics
|
{:topics topics
|
||||||
:from from
|
;; To is currently not sent to the mailserver, but we use to calculate
|
||||||
:to to})))
|
;; when the last-request was sent.
|
||||||
|
:to now-in-s
|
||||||
|
:from (max last-request
|
||||||
|
(- now-in-s one-day))}))
|
||||||
|
|
||||||
(defn prepare-messages-requests
|
(defn prepare-messages-requests
|
||||||
[{:keys [db now] :as cofx} request-to]
|
[{:keys [db now] :as cofx} request-to]
|
||||||
(let [web3 (:web3 db)]
|
(let [web3 (:web3 db)]
|
||||||
(remove nil?
|
(->>
|
||||||
(mapcat (partial split-request-per-day request-to)
|
(:mailserver/topics db)
|
||||||
(reduce (fn [acc [topic {:keys [last-request]}]]
|
(reduce (fn [acc [topic {:keys [last-request]}]]
|
||||||
(update acc last-request conj topic))
|
(update acc last-request conj topic))
|
||||||
{}
|
{})
|
||||||
(:mailserver/topics db))))))
|
(keep (partial ->request request-to)))))
|
||||||
|
|
||||||
(fx/defn process-next-messages-request
|
(fx/defn process-next-messages-request
|
||||||
[{:keys [db now] :as cofx}]
|
[{:keys [db now] :as cofx}]
|
||||||
|
|
Loading…
Reference in New Issue