Add cache preloaded hint to avoid duplicate infoInCache CBs in commit
authorMichael Andres <ma@suse.de>
Fri, 16 May 2014 11:53:05 +0000 (13:53 +0200)
committerMichael Andres <ma@suse.de>
Tue, 27 May 2014 14:30:30 +0000 (16:30 +0200)
zypp/target/CommitPackageCache.cc
zypp/target/CommitPackageCache.h
zypp/target/CommitPackageCacheImpl.h
zypp/target/CommitPackageCacheReadAhead.cc
zypp/target/TargetImpl.cc

index 6aa4dca..07a51c4 100644 (file)
@@ -127,13 +127,17 @@ namespace zypp
     {}
 
     void CommitPackageCache::setCommitList( std::vector<sat::Solvable> commitList_r )
-    {
-      _pimpl->setCommitList( commitList_r );
-    }
+    { _pimpl->setCommitList( commitList_r ); }
 
     ManagedFile CommitPackageCache::get( const PoolItem & citem_r )
     { return _pimpl->get( citem_r ); }
 
+    bool CommitPackageCache::preloaded() const
+    { return _pimpl->preloaded(); }
+
+    void CommitPackageCache::preloaded( bool newval_r )
+    { _pimpl->preloaded( newval_r ); }
+
     /******************************************************************
     **
     ** FUNCTION NAME : operator<<
index aac5ac6..2cf6220 100644 (file)
@@ -84,6 +84,14 @@ namespace zypp
       ManagedFile get( sat::Solvable citem_r )
       { return get( PoolItem(citem_r) ); }
 
+      /** Whether preloaded hint is set.
+       * If preloaded the cache tries to avoid trigering the infoInCache CB,
+       * based on the assumption this was already done when preloading the cache.
+       */
+      bool preloaded() const;
+      /** Set preloaded hint. */
+      void preloaded( bool newval_r );
+
     public:
       /** Implementation. */
       class Impl;
index 3718e8b..c7ac702 100644 (file)
@@ -64,6 +64,12 @@ namespace zypp
       const std::vector<sat::Solvable> & commitList() const
       { return _commitList; }
 
+      bool preloaded() const
+      { return _preloaded; }
+
+      void preloaded( bool newval_r )
+      { _preloaded = newval_r; }
+
     protected:
       /** Let the Source provide the package. */
       virtual ManagedFile sourceProvidePackage( const PoolItem & pi ) const
@@ -96,6 +102,7 @@ namespace zypp
     private:
       std::vector<sat::Solvable> _commitList;
       PackageProvider _packageProvider;
+      DefaultIntegral<bool,false> _preloaded;
     };
     ///////////////////////////////////////////////////////////////////
 
index d9c5c92..826f5d2 100644 (file)
@@ -140,27 +140,39 @@ namespace zypp
     //
     ManagedFile CommitPackageCacheReadAhead::get( const PoolItem & citem_r )
     {
-      // Non CD/DVD media provide their packages without cache.
-      if ( ! onInteractiveMedia( citem_r ) )
+      ManagedFile ret;
+      if ( preloaded() )
       {
-       return sourceProvidePackage( citem_r );
+       // Check whether it's cached.
+       ManagedFile ret( sourceProvideCachedPackage( citem_r ) );
+       if ( ! ret->empty() )
+         return ret;
       }
+      // else: we head for sourceProvidePackage(), even if the package
+      // was cached. The actual difference is that sourceProvidePackage
+      // will trigger the infoInCache CB that informs the application.
+      // Once the cache is preloaded we try to avoid this CB.
 
-      // Check whether it's cached.
-      ManagedFile ret( sourceProvideCachedPackage( citem_r ) );
-      if ( ! ret->empty() )
-       return ret;
 
-      IMediaKey current( citem_r );
-      if ( current != _lastInteractive )
+      // Preload cache if a CD/DVD change is pending to avoid
+      // switching back and forth...
+      if ( onInteractiveMedia( citem_r ) )
       {
-       if ( _lastInteractive != IMediaKey() )
+       ret = sourceProvideCachedPackage( citem_r );
+       if ( ! ret->empty() )
+         return ret;
+
+       IMediaKey current( citem_r );
+       if ( current != _lastInteractive )
        {
-         cacheLastInteractive( citem_r );
-       }
+         if ( _lastInteractive != IMediaKey() )
+         {
+           cacheLastInteractive( citem_r );
+         }
 
-       DBG << "Interactive change [" << ++_dbgChanges << "] from " << _lastInteractive << " to " << current << endl;
-       _lastInteractive = current;
+         DBG << "Interactive change [" << ++_dbgChanges << "] from " << _lastInteractive << " to " << current << endl;
+         _lastInteractive = current;
+       }
       }
 
       // Provide and return the file from media.
index 72ffe35..5dd2459 100644 (file)
@@ -1449,6 +1449,7 @@ namespace zypp
               }
             }
           }
+          packageCache.preloaded( true ); // try to avoid duplicate infoInCache CBs in commit
         }
 
         if ( miss )