Towards a proper fix for bug #6846, this just disentangles a couple

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
This commit is contained in:
Richard Heck 2010-12-03 19:00:55 +00:00
parent 4efd89fe83
commit ab47822680
3 changed files with 45 additions and 23 deletions

View 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;
}
}
}
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;
// if not valid, then reload the info
if (!d->bibinfo_cache_valid_) {
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.

View 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;

View 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();
}