From: Richard Heck Date: Thu, 5 Jun 2008 06:42:53 +0000 (+0000) Subject: Fix some of the BibTeX cache issues. We need to be able to invalidate the cache when X-Git-Tag: 1.6.10~4504 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2ea039ba9938d3688072ddad72803e1bfb2a67b1;p=lyx.git Fix some of the BibTeX cache issues. We need to be able to invalidate the cache when InsetBibtex's get created and destroyed, or modified. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25136 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 632826fbc6..377b9ef2a3 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -210,6 +210,8 @@ public: // file, and then to construct the Buffer's bibinfo from that. /// A cache for bibliography info mutable BiblioInfo bibinfo_; + /// whether the bibinfo cache is valid + bool bibinfoCacheValid_; /// Cache of timestamps of .bib files map bibfileStatus_; @@ -243,7 +245,7 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_) : parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_), filename(file), file_fully_loaded(false), toc_backend(&parent), macro_lock(false), timestamp_(0), - checksum_(0), wa_(0), undo_(parent) + checksum_(0), wa_(0), undo_(parent), bibinfoCacheValid_(false) { temppath = createBufferTmpDir(); lyxvc.setBuffer(&parent); @@ -1346,6 +1348,14 @@ void Buffer::updateBibfilesCache() const bibfiles.end()); } } + // the bibinfo cache is now invalid + d->bibinfoCacheValid_ = false; +} + + +void Buffer::invalidateBibfilesCache() +{ + d->bibinfoCacheValid_ = false; } @@ -1377,23 +1387,26 @@ BiblioInfo const & Buffer::masterBibInfo() const BiblioInfo const & Buffer::localBibInfo() const { - support::FileNameList const & bibfilesCache = getBibfilesCache(); - // compare the cached timestamps with the actual ones. - bool changed = false; - support::FileNameList::const_iterator ei = bibfilesCache.begin(); - support::FileNameList::const_iterator en = bibfilesCache.end(); - for (; ei != en; ++ ei) { - time_t lastw = ei->lastModified(); - if (lastw != d->bibfileStatus_[*ei]) { - changed = true; - d->bibfileStatus_[*ei] = lastw; - break; + if (d->bibinfoCacheValid_) { + support::FileNameList const & bibfilesCache = getBibfilesCache(); + // compare the cached timestamps with the actual ones. + support::FileNameList::const_iterator ei = bibfilesCache.begin(); + support::FileNameList::const_iterator en = bibfilesCache.end(); + for (; ei != en; ++ ei) { + time_t lastw = ei->lastModified(); + if (lastw != d->bibfileStatus_[*ei]) { + d->bibinfoCacheValid_ = false; + d->bibfileStatus_[*ei] = lastw; + break; + } } } - if (changed) { + if (!d->bibinfoCacheValid_) { + d->bibinfo_.clear(); for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) it->fillWithBibKeys(d->bibinfo_, it); + d->bibinfoCacheValid_ = true; } return d->bibinfo_; } diff --git a/src/Buffer.h b/src/Buffer.h index 95d1386866..f50d002394 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -306,6 +306,8 @@ public: /// Update the cache with all bibfiles in use (including bibfiles /// of loaded child documents). void updateBibfilesCache() const; + /// + void invalidateBibfilesCache(); /// Return the cache with all bibfiles in use (including bibfiles /// of loaded child documents). support::FileNameList const & getBibfilesCache() const; diff --git a/src/factory.cpp b/src/factory.cpp index 2646a3c6ca..18b733f06a 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -233,7 +233,7 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd) case BIBTEX_CODE: { InsetCommandParams icp(code); InsetCommand::string2params(name, to_utf8(cmd.argument()), icp); - return new InsetBibtex(icp); + return new InsetBibtex(buf, icp); } case CITE_CODE: { @@ -454,7 +454,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf) inset.reset(new InsetBibitem(inscmd)); break; case BIBTEX_CODE: - inset.reset(new InsetBibtex(inscmd)); + inset.reset(new InsetBibtex(buf, inscmd)); break; case CITE_CODE: inset.reset(new InsetCitation(inscmd)); diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 55a20edefb..3546ccf37b 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -49,9 +49,19 @@ namespace Alert = frontend::Alert; namespace os = support::os; -InsetBibtex::InsetBibtex(InsetCommandParams const & p) +InsetBibtex::InsetBibtex(Buffer const & buf, InsetCommandParams const & p) : InsetCommand(p, "bibtex") -{} +{ + Inset::setBuffer(const_cast(buf)); + buffer_->invalidateBibfilesCache(); +} + + +InsetBibtex::~InsetBibtex() +{ + if (buffer_) + buffer_->invalidateBibfilesCache(); +} ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */) diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index e8bd176b70..ad6e064e71 100644 --- a/src/insets/InsetBibtex.h +++ b/src/insets/InsetBibtex.h @@ -26,7 +26,9 @@ namespace lyx { class InsetBibtex : public InsetCommand { public: /// - InsetBibtex(InsetCommandParams const &); + InsetBibtex(Buffer const &, InsetCommandParams const &); + /// + virtual ~InsetBibtex(); /// docstring screenLabel() const; ///