Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Link Creation Reporting #2100

Merged
merged 5 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/cljc/athens/common_db.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -586,17 +586,13 @@
(defn string->lookup-refs
"Given string s, compute the set of refs expressed as Datalog lookup refs."
[s]
(let [ast (parser/structure-parse-to-ast s)
block-ref-str->uid #(strip-markup % "((" "))")
page-ref-str->title #(or (strip-markup % "#[[" "]]")
(strip-markup % "[[" "]]")
(strip-markup % "#" ""))
block-lookups (into #{}
(map (fn [uid] [:block/uid uid]))
(extract-tag-values ast #{:block-ref} identity #(-> % second :from block-ref-str->uid)))
page-lookups (into #{}
(map (fn [title] [:node/title title]))
(extract-tag-values ast #{:page-link :hashtag} identity #(-> % second :from page-ref-str->title)))]
(let [ast (parser/structure-parse-to-ast s)
block-lookups (into #{}
(map (fn [uid] [:block/uid uid]))
(extract-tag-values ast #{:block-ref} identity #(-> % second :string)))
page-lookups (into #{}
(map (fn [title] [:node/title title]))
(extract-tag-values ast #{:page-link :hashtag} identity #(-> % second :string)))]
(set/union block-lookups page-lookups)))


Expand Down
37 changes: 37 additions & 0 deletions src/cljc/athens/common_events/graph/ops.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[athens.common-db :as common-db]
[athens.common-events.graph.atomic :as atomic]
[athens.common-events.graph.composite :as composite]
[athens.parser.structure :as structure]
[clojure.set :as set]))


Expand Down Expand Up @@ -195,3 +196,39 @@
(map :block/new)
set)]
new-uids))


(defn structural-diff
neotyk marked this conversation as resolved.
Show resolved Hide resolved
"Calculates removed and added links (block refs & page links)"
[db ops]
(let [block-save-ops (contains-op? ops :block/save)
neotyk marked this conversation as resolved.
Show resolved Hide resolved
new-blocks (->> block-save-ops
(map #(select-keys (:op/args %)
[:block/uid :block/string])))
new-block-uids (->> new-blocks
(map :block/uid)
set)
new-structures (->> new-blocks
(map :block/string)
(map structure/structure-parser->ast))
old-block-strings (->> new-block-uids
filipesilva marked this conversation as resolved.
Show resolved Hide resolved
(map #(common-db/get-block-string db %)))
old-structures (->> old-block-strings
(map structure/structure-parser->ast))
links (fn [structs names renames]
(->> structs
(mapcat (partial tree-seq vector? identity))
(filter #(and (vector? %)
(contains? names (first %))))
(map #(vector (get renames (first %) (first %))
(-> % second :string)))
set))
old-links (links old-structures
#{:page-link :hashtag :block-ref}
{:hashtag :page-link})
new-links (links new-structures
#{:page-link :hashtag :block-ref}
{:hashtag :page-link})
removed-links (set/difference old-links new-links)
added-links (set/difference new-links old-links)]
[removed-links added-links]))
neotyk marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 18 additions & 9 deletions src/cljc/athens/parser/structure.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,42 @@

(defn page-link-transform
[& contents]
(apply conj [:page-link {:from (str "[[" (apply string-representation contents) "]]")}]
contents))
(let [string-repr (apply string-representation contents)]
(apply conj [:page-link {:from (str "[[" string-repr "]]")
:string string-repr}]
contents)))


(defn naked-hashtag-transform
[& contents]
(apply conj [:hashtag {:from (str "#" (apply string-representation contents))}]
contents))
(let [string-repr (apply string-representation contents)]
(apply conj [:hashtag {:from (str "#" string-repr)
:string string-repr}]
contents)))


(defn braced-hashtag-transform
[& contents]
(apply conj [:hashtag {:from (str "#[[" (apply string-representation contents) "]]")}]
contents))
(let [string-repr (apply string-representation contents)]
(apply conj [:hashtag {:from (str "#[[" string-repr "]]")
:string string-repr}]
contents)))


(defn block-ref-transform
[block-ref-str]
[:block-ref {:from (str "((" block-ref-str "))")}
[:block-ref {:from (str "((" block-ref-str "))")
:string block-ref-str}
block-ref-str])


(defn typed-block-ref-transform
[ref-type-el block-ref-el]
(let [ref-type (second ref-type-el)
block-ref-from (-> block-ref-el second :from)]
[:typed-block-ref {:from (str "{{" ref-type ": " block-ref-from "}}")}
block-ref-from (-> block-ref-el second :from)
string-repr (str ref-type ": " block-ref-from)]
[:typed-block-ref {:from (str "{{" string-repr "}}")
:string string-repr}
ref-type-el
block-ref-el]))

Expand Down
31 changes: 31 additions & 0 deletions src/cljs/athens/electron/monitoring/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,34 @@
{:posthog/capture-event! {:event-name "feature/block.create"
:opts-map {:source source
:blocks-created count}}}))


(rf/reg-event-fx
:reporting/page.link
(fn [{:keys [_db]} [_ {:keys [source count]}]]
{:posthog/capture-event! {:event-name "feature/page.link"
:opts-map {:source source
:links-created count}}}))


(rf/reg-event-fx
:reporting/block.link
(fn [{:keys [_db]} [_ {:keys [source count]}]]
{:posthog/capture-event! {:event-name "feature/block.link"
:opts-map {:source source
:links-created count}}}))


(defn build-reporting-link-creation
[added source]
(let [{:keys [page-link block-ref]} (reduce (fn [agg [link-type _]]
filipesilva marked this conversation as resolved.
Show resolved Hide resolved
(update agg link-type (fnil inc 0)))
{}
added)]
(cond-> []
(pos? page-link)
(conj [:reporting/page.link {:source source
:count page-link}])
(pos? block-ref)
(conj [:reporting/block.link {:source source
:count page-link}]))))
Loading