]> git.lyx.org Git - features.git/commitdiff
Towards a proper fix for bug #6846, this just disentangles a couple
authorRichard Heck <rgheck@comcast.net>
Fri, 3 Dec 2010 19:00:55 +0000 (19:00 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 3 Dec 2010 19:00:55 +0000 (19:00 +0000)
things we will ultimately want to do separately.

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

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

index 5ee983f301fa15870cbb88b044ff1766010cbbb3..c840564574e07f8ebd9114f7316d6ffed58358da 100644 (file)
@@ -1809,21 +1809,25 @@ BiblioInfo const & Buffer::masterBibInfo() const
 }
 
 
-void Buffer::checkBibInfoCache() const 
+bool Buffer::isBibInfoCacheValid() const
+{
+       return d->bibinfo_cache_valid_;
+}
+
+
+void Buffer::checkIfBibInfoCacheIsValid() const
 {
        // use the master's cache
        Buffer const * const tmp = masterBuffer();
        if (tmp != this) {
-               tmp->checkBibInfoCache();
+               tmp->checkIfBibInfoCacheIsValid();
                return;
        }
 
-       // this will also reload the cache if it is invalid 
-       support::FileNameList const & bibfiles_cache = getBibfilesCache();
-       
        // compare the cached timestamps with the actual ones.
-       support::FileNameList::const_iterator ei = bibfiles_cache.begin();
-       support::FileNameList::const_iterator en = bibfiles_cache.end();
+       FileNameList const & bibfiles_cache = getBibfilesCache();
+       FileNameList::const_iterator ei = bibfiles_cache.begin();
+       FileNameList::const_iterator en = bibfiles_cache.end();
        for (; ei != en; ++ ei) {
                time_t lastw = ei->lastModified();
                time_t prevw = d->bibfile_status_[*ei];
@@ -1832,13 +1836,25 @@ void Buffer::checkBibInfoCache() const
                        d->bibfile_status_[*ei] = lastw;
                }
        }
-       
-       // if not valid, then reload the info
-       if (!d->bibinfo_cache_valid_) {
-               d->bibinfo_.clear();
-               fillWithBibKeys(d->bibinfo_);
-               d->bibinfo_cache_valid_ = true;
+}
+
+
+void Buffer::reloadBibInfoCache() const
+{
+       // use the master's cache
+       Buffer const * const tmp = masterBuffer();
+       if (tmp != this) {
+               tmp->reloadBibInfoCache();
+               return;
        }
+
+       checkIfBibInfoCacheIsValid();
+       if (d->bibinfo_cache_valid_)
+               return;
+
+       d->bibinfo_.clear();
+       fillWithBibKeys(d->bibinfo_);
+       d->bibinfo_cache_valid_ = true;
 }
 
 
@@ -3014,9 +3030,9 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
        //FIXME: This does not work for child documents yet.
        LASSERT(code == CITE_CODE, /**/);
 
-       // Check if the label 'from' appears more than once
-       checkBibInfoCache();
+       reloadBibInfoCache();
 
+       // Check if the label 'from' appears more than once
        BiblioInfo const & keys = masterBibInfo();
        BiblioInfo::const_iterator bit  = keys.begin();
        BiblioInfo::const_iterator bend = keys.end();
@@ -3829,7 +3845,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
        
        // do this only if we are the top-level Buffer
        if (master == this)
-               checkBibInfoCache();
+               reloadBibInfoCache();
 
        // 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 b91f36ffe67e35e2382e0bd9f0e27562e67fb06b..355ff332896575b18ad8a53320c16f645070761f 100644 (file)
@@ -441,12 +441,13 @@ public:
        void invalidateBibinfoCache() const;
        /// This invalidates the cache of files we need to check.
        void invalidateBibfileCache() const;
-       /// 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
-       /// updateBuffer() and from GuiCitation.)
+       /// Updates the cached bibliography information, checking first to see
+       /// whether the cache is valid. If so, we do nothing. If not, then we
+       /// reload all the BibTeX info.
        /// Note that this operates on the master document.
-       void checkBibInfoCache() const;
+       void reloadBibInfoCache() const;
+       /// Was the cache valid the last time we checked?
+       bool isBibInfoCacheValid() const;
        /// \return the bibliography information for this buffer's master,
        /// or just for it, if it isn't a child.
        BiblioInfo const & masterBibInfo() const;
@@ -660,6 +661,10 @@ private:
        std::vector<std::string> backends() const;
        ///
        void getLanguages(std::set<Language const *> &) const;
+       /// Checks whether any of the referenced bibfiles have changed since the
+       /// last time we loaded the cache. Note that this does NOT update the
+       /// cached information.
+       void checkIfBibInfoCacheIsValid() const;
        /// Update the list of all bibfiles in use (including bibfiles
        /// of loaded child documents).
        void updateBibfilesCache(UpdateScope scope = UpdateMaster) const;
index ba13fd4280ae312f57a2dcbc6b086c59f4792f25..9da6f1016d3d3da83e432006114a2d5dbcba5e7a 100644 (file)
@@ -757,8 +757,9 @@ void GuiCitation::dispatchParams()
 
 BiblioInfo const & GuiCitation::bibInfo() const
 {
-       buffer().checkBibInfoCache();
-       return buffer().masterBibInfo();
+       Buffer const & buf = buffer();
+       buf.reloadBibInfoCache();
+       return buf.masterBibInfo();
 }