]> git.lyx.org Git - features.git/commitdiff
Check the bibliography cache only when we really need to do so. This (a)
authorRichard Heck <rgheck@comcast.net>
Mon, 11 Jan 2010 16:29:26 +0000 (16:29 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 11 Jan 2010 16:29:26 +0000 (16:29 +0000)
prevents weirdness that might happen if the .bib file were to change
during updateLabels(), (b) prevents even further weirdness that might
happen if it changed during the output routines, and (c) ought to avoid
slowness caused by the repeated calls to QFileInfo::refresh() needed to
check the cache status.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32972 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/frontends/qt4/GuiCitation.cpp

index fbf288db42bd8ffca05cf3cd3b49f299586f681d..5288a4f422a106e1c05428c741813578f8b64112 100644 (file)
@@ -1671,7 +1671,6 @@ BiblioInfo const & Buffer::masterBibInfo() const
 
 BiblioInfo const & Buffer::localBibInfo() const
 {
-       checkBibInfoCache();
        return d->bibinfo_;
 }
 
@@ -2822,6 +2821,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
        // Check if the label 'from' appears more than once
        vector<docstring> labels;
        string paramName;
+       checkBibInfoCache();
        BiblioInfo const & keys = masterBibInfo();
        BiblioInfo::const_iterator bit  = keys.begin();
        BiblioInfo::const_iterator bend = keys.end();
@@ -3494,6 +3494,10 @@ void Buffer::updateLabels(UpdateScope scope, bool out) const
        // Use the master text class also for child documents
        Buffer const * const master = masterBuffer();
        DocumentClass const & textclass = master->params().documentClass();
+       
+       // do this only if we are the top-level Buffer
+       if (scope != UpdateMaster || master == this)
+               checkBibInfoCache();
 
        // keep the buffers to be children in this set. If the call from the
        // master comes back we can see which of them were actually seen (i.e.
index 6581313965fc2961dde062ee5389ac409e9149d6..297e63208ce126bf5110d47a62f428f3292ffd73 100644 (file)
@@ -350,15 +350,23 @@ public:
        */
        void validate(LaTeXFeatures &) const;
 
-       /// Update the cache with all bibfiles in use (including bibfiles
+       /// Update the list of all bibfiles in use (including bibfiles
        /// of loaded child documents).
        void updateBibfilesCache(UpdateScope scope = UpdateMaster) const;
-       ///
-       void invalidateBibinfoCache();
-       /// Return the cache with all bibfiles in use (including bibfiles
+       /// Return the list with all bibfiles in use (including bibfiles
        /// of loaded child documents).
        support::FileNameList const & 
                getBibfilesCache(UpdateScope scope = UpdateMaster) const;
+       /// Information from BibTeX databases is cached in the Buffer, so
+       /// we do not have to read the file over and over. 
+       /// Calling this method invalidates the cache and so requires a
+       /// re-read.
+       void invalidateBibinfoCache();
+       /// Updates the cached bibliography information.
+       /// Note that you MUST call this method to update the cache. It will
+       /// not happen otherwise. (Currently, it is called at the start of
+       /// updateLabels() and from GuiCitation.)
+       void checkBibInfoCache() const;
        /// \return the bibliography information for this buffer's master,
        /// or just for it, if it isn't a child.
        BiblioInfo const & masterBibInfo() const;
@@ -571,8 +579,6 @@ private:
        void updateMacros(DocIterator & it,
                                     DocIterator & scope) const;
        ///
-       void checkBibInfoCache() const;
-       ///
        void setLabel(ParIterator & it) const;
        ///
        void collectRelatives(BufferSet & bufs) const;
index 7fc2cf5d99f62da8f65bc24c83cc90823e02a439..4a55df9ffc4d1bbd0ab6e0073d7e79027c908eb7 100644 (file)
@@ -735,6 +735,7 @@ void GuiCitation::dispatchParams()
 
 BiblioInfo const & GuiCitation::bibInfo() const
 {
+       buffer().checkBibInfoCache();
        return buffer().masterBibInfo();
 }