Skip to content

Commit

Permalink
improve polling performance
Browse files Browse the repository at this point in the history
  • Loading branch information
goktug97 committed Sep 26, 2020
1 parent 467b787 commit 608fc38
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions org-roam-server.el
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
buffer-file-name)))
"."))

(defvar org-roam-server-db-last-modification nil)

(defgroup org-roam-server nil
"org-roam-server customizable variables."
:group 'org-roam)
Expand Down Expand Up @@ -514,14 +516,25 @@ DESCRIPTION is the shown attribute to the user if the image is not rendered."
(if org-roam-server-authenticate
(if (not (string= org-roam-server-token token))
(httpd-error httpd-current-proc 403)))
(when (or force org-roam-server-network-poll)
(let* ((node-query `[:select [titles:file titles:title tags] :from titles
:left :outer :join tags :on (= titles:file tags:file)
,@(org-roam-graph--expand-matcher 'titles:file t)])
(data (org-roam-server-visjs-json node-query)))
(when (or force (not (string= data org-roam-server-data)))
(setq org-roam-server-data data)
(insert (format "data: %s\n\n" org-roam-server-data))))))
(let (
(node-query `[:select [titles:file titles:title tags] :from titles
:left :outer :join tags :on (= titles:file tags:file)
,@(org-roam-graph--expand-matcher 'titles:file t)]))
(if force
(insert (format "data: %s\n\n"
(org-roam-server-visjs-json node-query)))
(when (and org-roam-server-network-poll
(or (not org-roam-server-db-last-modification)
(not (eq org-roam-server-db-last-modification
(floor (float-time
(file-attribute-modification-time
(file-attributes (org-roam-db--get)))))))))
(let ((data (org-roam-server-visjs-json node-query)))
(setq org-roam-server-db-last-modification
(floor (float-time
(file-attribute-modification-time
(file-attributes (org-roam-db--get))))))
(insert (format "data: %s\n\n" data)))))))

(defservlet* network-vis-options application/json (token)
(if org-roam-server-authenticate
Expand Down

0 comments on commit 608fc38

Please sign in to comment.