From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] Fix and optimize publishing cache check Date: Thu, 14 Aug 2014 11:13:32 +0200 Message-ID: <878umr4eo3.fsf@nicolasgoaziou.fr> References: <87oavpyhvn.fsf@fastmail.fm> <87d2c5xb5a.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHr5f-0003jk-7Q for emacs-orgmode@gnu.org; Thu, 14 Aug 2014 05:13:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHr5X-0000Id-3y for emacs-orgmode@gnu.org; Thu, 14 Aug 2014 05:12:59 -0400 Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]:52117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHr5W-0000IX-UB for emacs-orgmode@gnu.org; Thu, 14 Aug 2014 05:12:51 -0400 In-Reply-To: <87d2c5xb5a.fsf@fastmail.fm> (Matt Lundin's message of "Tue, 12 Aug 2014 23:32:17 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matt Lundin Cc: Org Mode Hello, Matt Lundin writes: > Here is an improved version of the previous patch (please apply it > rather than the previous). Thank you for the patch. > This version further optimizes cache checking by only calling > find-buffer-visiting if necessary. (It also fixes some long lines.) On > a test project containing 5000 files, running org-publish on the > project with the cache enabled now takes seconds rather than minutes. Great. > + (ctime (org-publish-cache-ctime-of-src filename)) > + (needsp (or (null pstamp) (< pstamp ctime))) > + includes) > + ;; if the file needs publishing, refresh the included-files cache property Comments need to start with a capital and end with a period. > + (when (and needsp > + (equal (file-name-extension filename) "org")) > + (let ((visiting (find-buffer-visiting filename)) > + (buf (find-file-noselect (expand-file-name filename)))) > + (with-current-buffer buf > + (save-excursion > + (goto-char (point-min)) > + (while (re-search-forward "^[ \t]*#\\+INCLUDE:" nil t) > + (let* ((element (org-element-at-point)) > + (included-file > + (and (eq (org-element-type element) 'keyword) > + (let ((value (org-element-property :value element))) > + (and value > + (string-match "^\\(\".+?\"\\|\\S-+\\)" value) > + (org-remove-double-quotes > + (match-string 1 value))))))) > + (when included-file > + (add-to-list 'includes (expand-file-name included-file))))))) > + (unless visiting (kill-buffer buf)) Do not kill buffer yet, since you may re-open it later. > + (when includes > + (org-publish-cache-set-file-property filename :includes includes)))) > + ;; return t if needsp or if included files have changed Ditto. > + (or needsp > + (when (delq nil > + (mapcar (lambda (file) > + (let ((ct (org-publish-cache-ctime-of-src file))) > + (and (file-exists-p file) > + (< ctime ct)))) > + (org-publish-cache-get-file-property filename :includes))) (when (delq nil (mapcar PREDICATE LIST))) => (org-some PREDICATE LIST) > + ;; update the timestamp of the published file if buffer is not modified Ditto. > + (let ((visiting (find-buffer-visiting filename)) > + (buf (find-file-noselect (expand-file-name filename)))) > + (with-current-buffer buf Not needed if you didn't kill buffer yet. > + (when (not (buffer-modified-p)) (unless ...) > + (set-buffer-modified-p t) (save-buffer))) Hmm. Would `set-file-times' do the job? > + (unless visiting (kill-buffer buf))) > + t)))) You can now kill-buffer, but for all cases. Regards, -- Nicolas Goaziou