Update crawled peers with most-commonly used nick for each URL
authorSiraaj Khandkar <siraaj@khandkar.net>
Tue, 30 Nov 2021 22:54:59 +0000 (17:54 -0500)
committerSiraaj Khandkar <siraaj@khandkar.net>
Tue, 30 Nov 2021 22:54:59 +0000 (17:54 -0500)
info.rkt
tt.rkt

index a9a551a..dc8a3af 100644 (file)
--- 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 <siraaj@khandkar.net>"))
 (define deps
diff --git a/tt.rkt b/tt.rkt
index f654f15..e002e71 100644 (file)
--- a/tt.rkt
+++ b/tt.rkt
     (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)
 (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)]
            (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
          [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)))]
                                (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
This page took 0.031757 seconds and 4 git commands to generate.