From: Richard Heck Date: Tue, 10 Aug 2010 14:12:48 +0000 (+0000) Subject: Fix some bugs in the bibinfo caching mechanism. Comments to follow. X-Git-Tag: 2.0.0~2822 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2203d7aa0a8e9d64666498fb26eb17f699c2f52b;p=features.git Fix some bugs in the bibinfo caching mechanism. Comments to follow. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35112 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index c64590573e..5a228f4cc3 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -255,9 +255,9 @@ public: /// A cache for bibliography info mutable BiblioInfo bibinfo_; /// whether the bibinfo cache is valid - bool bibinfo_cache_valid_; + mutable bool bibinfo_cache_valid_; /// whether the bibfile cache is valid - bool bibfile_cache_valid_; + mutable bool bibfile_cache_valid_; /// Cache of timestamps of .bib files map bibfile_status_; @@ -1698,6 +1698,7 @@ void Buffer::getLabelList(vector & list) const void Buffer::updateBibfilesCache(UpdateScope scope) const { + // FIXME This is probably unnecssary, given where we call this. // If this is a child document, use the parent's cache instead. Buffer const * const pbuf = d->parent(); if (pbuf && scope != UpdateChildOnly) { @@ -1714,47 +1715,53 @@ void Buffer::updateBibfilesCache(UpdateScope scope) const d->bibfiles_cache_.insert(d->bibfiles_cache_.end(), bibfiles.begin(), bibfiles.end()); - // the bibinfo cache is now invalid - d->bibinfo_cache_valid_ = false; } else if (it->lyxCode() == INCLUDE_CODE) { InsetInclude & inset = static_cast(*it); Buffer const * const incbuf = inset.getChildBuffer(); if (!incbuf) continue; - incbuf->updateBibfilesCache(UpdateChildOnly); support::FileNameList const & bibfiles = incbuf->getBibfilesCache(UpdateChildOnly); if (!bibfiles.empty()) { d->bibfiles_cache_.insert(d->bibfiles_cache_.end(), bibfiles.begin(), bibfiles.end()); - // the bibinfo cache is now invalid - d->bibinfo_cache_valid_ = false; } } } d->bibfile_cache_valid_ = true; + d->bibinfo_cache_valid_ = false; } -void Buffer::invalidateBibinfoCache() +void Buffer::invalidateBibinfoCache() const { d->bibinfo_cache_valid_ = false; + // also invalidate the cache for the parent buffer + Buffer const * const pbuf = d->parent(); + if (pbuf) + pbuf->invalidateBibinfoCache(); } -void Buffer::invalidateBibfileCache() +void Buffer::invalidateBibfileCache() const { d->bibfile_cache_valid_ = false; - invalidateBibinfoCache(); + d->bibinfo_cache_valid_ = false; + // also invalidate the cache for the parent buffer + Buffer const * const pbuf = d->parent(); + if (pbuf) + pbuf->invalidateBibfileCache(); } + support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const { - // If this is a child document, use the parent's cache instead. - Buffer const * const pbuf = d->parent(); - if (pbuf && scope != UpdateChildOnly) + // FIXME This is probably unnecessary, given where we call this. + // If this is a child document, use the master's cache instead. + Buffer const * const pbuf = masterBuffer(); + if (pbuf != this && scope != UpdateChildOnly) return pbuf->getBibfilesCache(); if (!d->bibfile_cache_valid_) @@ -1766,28 +1773,28 @@ support::FileNameList const & Buffer::getBibfilesCache(UpdateScope scope) const BiblioInfo const & Buffer::masterBibInfo() const { - // if this is a child document and the parent is already loaded - // use the parent's list instead [ale990412] Buffer const * const tmp = masterBuffer(); - LASSERT(tmp, /**/); if (tmp != this) return tmp->masterBibInfo(); - return localBibInfo(); -} - - -BiblioInfo const & Buffer::localBibInfo() const -{ return d->bibinfo_; } void Buffer::checkBibInfoCache() const { - support::FileNameList const & bibfilesCache = getBibfilesCache(); + // use the master's cache + Buffer const * const tmp = masterBuffer(); + if (tmp != this) { + tmp->checkBibInfoCache(); + 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 = bibfilesCache.begin(); - support::FileNameList::const_iterator en = bibfilesCache.end(); + support::FileNameList::const_iterator ei = bibfiles_cache.begin(); + support::FileNameList::const_iterator en = bibfiles_cache.end(); for (; ei != en; ++ ei) { time_t lastw = ei->lastModified(); time_t prevw = d->bibfile_status_[*ei]; @@ -1796,15 +1803,20 @@ void Buffer::checkBibInfoCache() const d->bibfile_status_[*ei] = lastw; } } - - // FIXME Don't do this here, but instead gather them as we go through - // updateBuffer(). + + // if not valid, then reload the info if (!d->bibinfo_cache_valid_) { d->bibinfo_.clear(); - for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) - it->fillWithBibKeys(d->bibinfo_, it); + fillWithBibKeys(d->bibinfo_); d->bibinfo_cache_valid_ = true; - } + } +} + + +void Buffer::fillWithBibKeys(BiblioInfo & keys) const +{ + for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) + it->fillWithBibKeys(keys, it); } @@ -3705,7 +3717,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const DocumentClass const & textclass = master->params().documentClass(); // do this only if we are the top-level Buffer - if (scope != UpdateMaster || master == this) + if (master == this) checkBibInfoCache(); // keep the buffers to be children in this set. If the call from the diff --git a/src/Buffer.h b/src/Buffer.h index 5186994eaa..d1a591af06 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -346,19 +346,20 @@ public: /// 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(); + void invalidateBibinfoCache() const; /// This invalidates the cache of files we need to check. - void invalidateBibfileCache(); + 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.) + /// Note that this operates on the master document. 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; - /// \return the bibliography information for this buffer ONLY. - BiblioInfo const & localBibInfo() const; + /// + void fillWithBibKeys(BiblioInfo & keys) const; /// void getLabelList(std::vector &) const; diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index bb81956cf1..f1ac7bf479 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -835,12 +835,10 @@ void InsetInclude::validate(LaTeXFeatures & features) const void InsetInclude::fillWithBibKeys(BiblioInfo & keys, InsetIterator const & /*di*/) const { - if (loadIfNeeded()) { - string const included_file = includedFileName(buffer(), params()).absFileName(); - Buffer * tmp = theBufferList().getBuffer(FileName(included_file)); - BiblioInfo const & newkeys = tmp->localBibInfo(); - keys.mergeBiblioInfo(newkeys); - } + Buffer * child = loadIfNeeded(); + if (!child) + return; + child->fillWithBibKeys(keys); }