From: Siraaj Khandkar Date: Tue, 30 Nov 2021 22:54:59 +0000 (-0500) Subject: Update crawled peers with most-commonly used nick for each URL X-Git-Tag: 0.29.1~1 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=49df5062e6de6465e08f29a72f05c7592c1b2e98;hp=bb208ad54a7eca0246289712daf84b3709cd17cb;p=tt.git Update crawled peers with most-commonly used nick for each URL --- diff --git a/info.rkt b/info.rkt index a9a551a..dc8a3af 100644 --- a/info.rkt +++ b/info.rkt @@ -6,7 +6,7 @@ (define pkg-desc "twtxt client") (define version - "0.28.1") + "0.29.0") (define pkg-authors '("Siraaj Khandkar ")) (define deps diff --git a/tt.rkt b/tt.rkt index f654f15..e002e71 100644 --- a/tt.rkt +++ b/tt.rkt @@ -837,10 +837,10 @@ (hash) msgs)) -(: update-nicks-history (-> (Listof Msg) Void)) -(define (update-nicks-history msgs) +(: update-nicks-history-files (-> Nick-Hist Void)) +(define (update-nicks-history-files nick-hist) (hash-for-each - (msgs->nick-hist msgs) + nick-hist (λ (url nick->hist) (define path (build-path tt-home-dir "nicks" "seen" (uri-encode (url->string url)))) (make-parent-directory* path) @@ -874,6 +874,15 @@ (define (nick-hist-common nick-hist url) (nick-hist-most-by nick-hist url Hist-freq)) +(: peers-update-nick-to-common (-> Nick-Hist (Listof Peer) (Listof Peer))) +(define (peers-update-nick-to-common nick-hist peers) + (map + (λ (p) + (match (nick-hist-common nick-hist (Peer-uri p)) + [#f p] + [n (struct-copy Peer p [nick n])])) + peers)) + (module+ test (let* ([url-str "http://foo"] [url (string->url url-str)] @@ -918,6 +927,8 @@ (peers-cached)] [cached-timeline (peers->timeline peers-cached)] + [nick-hist + (msgs->nick-hist cached-timeline)] [peers-mentioned-curr (peers-mentioned cached-timeline)] [peers-mentioned-prev @@ -925,16 +936,14 @@ [peers-all-prev (file->peers peers-all-file)] [peers-mentioned - (begin - ; XXX Updating nicks before running peers-merge, - ; since peers-merge is expected to refer to it in the future. - (update-nicks-history cached-timeline) - (peers-merge peers-mentioned-prev - peers-mentioned-curr))] + (peers-merge peers-mentioned-prev + peers-mentioned-curr)] [peers-all - (peers-merge peers-mentioned - peers-all-prev - peers-cached)] + (peers-update-nick-to-common + nick-hist + (peers-merge peers-mentioned + peers-all-prev + peers-cached))] [peers-discovered (set->list (set-subtract (make-immutable-peers peers-all) (make-immutable-peers peers-all-prev)))] @@ -951,6 +960,7 @@ (match-lambda [(Peer n _ u c) (list n u c)]) peers-discovered))) + (update-nicks-history-files nick-hist) (peers->file peers-cached peers-cached-file) (peers->file peers-mentioned