Check the bibliography cache only when we really need to do so. This (a)

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
This commit is contained in:
Richard Heck 2010-01-11 16:29:26 +00:00
parent 9173c27897
commit ce87e6767c
3 changed files with 18 additions and 7 deletions

View File

@ -1671,7 +1671,6 @@ BiblioInfo const & Buffer::masterBibInfo() const
BiblioInfo const & Buffer::localBibInfo() const BiblioInfo const & Buffer::localBibInfo() const
{ {
checkBibInfoCache();
return d->bibinfo_; 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 // Check if the label 'from' appears more than once
vector<docstring> labels; vector<docstring> labels;
string paramName; string paramName;
checkBibInfoCache();
BiblioInfo const & keys = masterBibInfo(); BiblioInfo const & keys = masterBibInfo();
BiblioInfo::const_iterator bit = keys.begin(); BiblioInfo::const_iterator bit = keys.begin();
BiblioInfo::const_iterator bend = keys.end(); BiblioInfo::const_iterator bend = keys.end();
@ -3495,6 +3495,10 @@ void Buffer::updateLabels(UpdateScope scope, bool out) const
Buffer const * const master = masterBuffer(); Buffer const * const master = masterBuffer();
DocumentClass const & textclass = master->params().documentClass(); 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 // 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. // master comes back we can see which of them were actually seen (i.e.
// via an InsetInclude). The remaining ones in the set need still be updated. // via an InsetInclude). The remaining ones in the set need still be updated.

View File

@ -350,15 +350,23 @@ public:
*/ */
void validate(LaTeXFeatures &) const; 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). /// of loaded child documents).
void updateBibfilesCache(UpdateScope scope = UpdateMaster) const; void updateBibfilesCache(UpdateScope scope = UpdateMaster) const;
/// /// Return the list with all bibfiles in use (including bibfiles
void invalidateBibinfoCache();
/// Return the cache with all bibfiles in use (including bibfiles
/// of loaded child documents). /// of loaded child documents).
support::FileNameList const & support::FileNameList const &
getBibfilesCache(UpdateScope scope = UpdateMaster) 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, /// \return the bibliography information for this buffer's master,
/// or just for it, if it isn't a child. /// or just for it, if it isn't a child.
BiblioInfo const & masterBibInfo() const; BiblioInfo const & masterBibInfo() const;
@ -571,8 +579,6 @@ private:
void updateMacros(DocIterator & it, void updateMacros(DocIterator & it,
DocIterator & scope) const; DocIterator & scope) const;
/// ///
void checkBibInfoCache() const;
///
void setLabel(ParIterator & it) const; void setLabel(ParIterator & it) const;
/// ///
void collectRelatives(BufferSet & bufs) const; void collectRelatives(BufferSet & bufs) const;

View File

@ -735,6 +735,7 @@ void GuiCitation::dispatchParams()
BiblioInfo const & GuiCitation::bibInfo() const BiblioInfo const & GuiCitation::bibInfo() const
{ {
buffer().checkBibInfoCache();
return buffer().masterBibInfo(); return buffer().masterBibInfo();
} }