From 5b6b7ec123af296e91bdeb7f33d12743490e0175 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 3 Aug 2022 15:14:34 +0300 Subject: [PATCH] Delete khoj network connections on incremental search teardown on Emacs interface Currently only get into this state when debug breakpoints on backend are keeping the connection open and user exits khoj search from Emacs Results in a number of open connections that slow khoj down. --- src/interface/emacs/khoj.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index 85b0ee28..09a375a3 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -36,7 +36,6 @@ (require 'url) (require 'json) - (defcustom khoj--server-url "http://localhost:8000" "Location of Khoj API server." :group 'khoj @@ -200,7 +199,16 @@ query-url buffer-name))))) +(defun delete-open-network-connections-to-khoj () + "Delete all network connections to khoj server" + (dolist (proc (process-list)) + (let ((proc-buf (buffer-name (process-buffer proc))) + (khoj-network-proc-buf (string-join (split-string khoj--server-url "://") " "))) + (when (string-match (format "%s" khoj-network-proc-buf) proc-buf) + (delete-process proc))))) + (defun khoj--teardown-incremental-search () + (message "[Khoj]: Teardown Incremental Search") ;; remove advice to rerank results on normal exit from minibuffer (advice-remove 'exit-minibuffer #'khoj--minibuffer-exit-advice) ;; unset khoj minibuffer window @@ -208,6 +216,8 @@ ;; cancel rerank timer (when (timerp khoj--rerank-timer) (cancel-timer khoj--rerank-timer)) + ;; delete open connections to khoj + (delete-open-network-connections-to-khoj) ;; remove hooks for khoj incremental query and self (remove-hook 'post-command-hook #'khoj--incremental-search) (remove-hook 'minibuffer-exit-hook #'khoj--teardown-incremental-search))