]> git.lyx.org Git - lyx.git/commitdiff
Fix some of the BibTeX cache issues. We need to be able to invalidate the cache when
authorRichard Heck <rgheck@comcast.net>
Thu, 5 Jun 2008 06:42:53 +0000 (06:42 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 5 Jun 2008 06:42:53 +0000 (06:42 +0000)
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

src/Buffer.cpp
src/Buffer.h
src/factory.cpp
src/insets/InsetBibtex.cpp
src/insets/InsetBibtex.h

index 632826fbc6d8c485c52cbc37a1af46d7064affa3..377b9ef2a35b7d83e04e330e1a8a04f48f3812f3 100644 (file)
@@ -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<FileName, time_t> 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_;
 }
index 95d1386866874f118628f1d95f768a6b93072600..f50d00239423be0036257d8713456cf5bc381c2f 100644 (file)
@@ -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;
index 2646a3c6ca6d482572ce094e37f345a1ff33e408..18b733f06a7f498f825773fb637261fa1a90cc29 100644 (file)
@@ -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));
index 55a20edefb3578735703665f4764b394ca1400ef..3546ccf37bfa4fa1aec835db2c9eac6a3c34e108 100644 (file)
@@ -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<Buffer &>(buf));
+       buffer_->invalidateBibfilesCache();
+}
+
+
+InsetBibtex::~InsetBibtex()
+{
+       if (buffer_)
+               buffer_->invalidateBibfilesCache();
+}
 
 
 ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
index e8bd176b7072971cefa9ea8f2b57f68e4c57eedd..ad6e064e712ef58d418a065b415f1f4ddffd287e 100644 (file)
@@ -26,7 +26,9 @@ namespace lyx {
 class InsetBibtex : public InsetCommand {
 public:
        ///
-       InsetBibtex(InsetCommandParams const &);
+       InsetBibtex(Buffer const &, InsetCommandParams const &);
+       ///
+       virtual ~InsetBibtex();
        ///
        docstring screenLabel() const;
        ///