- Separate target init from adding resolvables, getting rid of the
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 4 Aug 2006 13:20:56 +0000 (13:20 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 4 Aug 2006 13:20:56 +0000 (13:20 +0000)
uggly bool flag.
- dont clear the store each time Target::resolvables is called
- Load target resolvables on demand by kind, keep them cached later
- add Target::resolvablesByKind(kind) to allow query specific kind
  without reading all kinds. Used to port TargetProduct, which
  was reading the whole rpm database only to displayy base product
  name in YaST help.
- commit to pkg-bindings and packager following.
- jsrain will port more stuff, especially inst_source which
  startup time should by reduced by half afterwards.

13 files changed:
devel/devel.dmacvicar/Makefile.am
devel/devel.dmacvicar/testbed.cc
testsuite/solver/src/deptestomatic.cc
testsuite/source/tests/source-read-test.cc
testsuite/target/tests/storagetargettest.cc
zypp/Target.cc
zypp/Target.h
zypp/ZYpp.cc
zypp/ZYpp.h
zypp/target/TargetImpl.cc
zypp/target/TargetImpl.h
zypp/zypp_detail/ZYppImpl.cc
zypp/zypp_detail/ZYppImpl.h

index 0ddf33b..ff4bdba 100644 (file)
@@ -11,7 +11,7 @@ AM_LDFLAGS =
 AM_CXXFLAGS =
 # gperf:       -pg
 
-LDADD =                -L$(top_srcdir)/zypp/.libs -lzypp -lboost_regex -lxml2 -lz
+LDADD =                -L$(top_srcdir)/zypp/.libs -L$(top_srcdir)/zypp2/.libs -lzypp -lzypp2 -lboost_regex -lxml2 -lz
 
 ## ##################################################
 
@@ -33,7 +33,7 @@ yumparser_LDFLAGS =   -static
 
 .PHONY:        always
 
-$(noinst_PROGRAMS):    $(top_srcdir)/zypp/lib@PACKAGE@.la
+$(noinst_PROGRAMS):    $(top_srcdir)/zypp/lib@PACKAGE@.la $(top_srcdir)/zypp2/lib@PACKAGE@2.la
 
 $(top_srcdir)/zypp/lib@PACKAGE@.la:     always
        $(MAKE) -C $(top_srcdir)/zypp
index 72e6de8..5e128c5 100644 (file)
 #include "zypp/KeyRing.h"
 #include "zypp/PublicKey.h"
 
+#include "zypp/ZYppFactory.h"
+
 #include "zypp/MediaSetAccess.h"
-#include "zypp/source/yum/YUMSourceCacher.h"
+#include "zypp2/source/yum/YUMSourceCacher.h"
 
 using namespace zypp::detail;
 
@@ -44,8 +46,11 @@ int main()
   //MIL << local << std::endl;
   try
   {
-    zypp::source::yum::YUMSourceCacher cacher(Pathname("/"));
-    cacher.cache( Url("http://ftp-1.gwdg.de/pub/opensuse/distribution/SL-OSS-factory/inst-source/suse"), Pathname("/"));
+    //zypp::source::yum::YUMSourceCacher cacher(Pathname("/"));
+    //cacher.cache( Url("dir:/space/tmp/factory-yum"), Pathname("/"));
+    ZYpp::Ptr z = getZYpp();
+    z->initTarget("/", false);
+    
   }
   catch ( const Exception &e )
   {
index c22ea7d..b5288d9 100644 (file)
@@ -451,7 +451,7 @@ print_solution (ResolverContext_Ptr context, int *count, ChecksumList & checksum
     if (mediaorder) {
        cout << endl;
        RESULT << "Media Order:" << endl << endl;
-       God->initTarget("/", true);                     // init, but don't populate pool
+       God->initTarget("/");                   // init, but don't populate pool
        Target::PoolItemList dellist;
        Target::PoolItemList inslist;
        Target::PoolItemList srclist;
index f740528..b1cbb7c 100644 (file)
@@ -65,7 +65,7 @@ int main( int argc, char * argv[] )
        cerr << "Can't aquire ZYPP lock" << endl;
        return 1;
     }
-    God->initTarget("/", false);
+    God->initTarget("/");
     int argpos = 1;
 
     while ( argpos  < argc - 1 )
index 76bad4d..00aacda 100644 (file)
@@ -496,7 +496,7 @@ struct StorageTargetTest
 
 int main()
 { 
-  getZYpp()->initTarget("/", false);
+  getZYpp()->initTarget("/");
   try
   {  
     //RUN_TEST(armstrong_yum_source_source_read);
index d664c4c..2258b54 100644 (file)
@@ -67,6 +67,9 @@ namespace zypp
   const ResStore & Target::resolvables()
   { return _pimpl->resolvables(); }
 
+  ResStore Target::resolvablesByKind( const Resolvable::Kind kind )
+  { return _pimpl->resolvablesByKind(kind); }
+
   target::rpm::RpmDb & Target::rpmDb()
   { return _pimpl->rpm(); }
 
index c521ddf..0730cad 100644 (file)
@@ -58,6 +58,14 @@ namespace zypp
     /** All resolvables provided by the target. */
     const ResStore & resolvables();
 
+    /**
+     * load resolvables of certain kind in the internal store
+     * and return a store with only that kind
+     * successive calls will be faster as resolvables are cached-
+     */
+    ResStore resolvablesByKind( const Resolvable::Kind kind );
+    
+
     /** Null implementation */
     static Target_Ptr nullimpl();
 
index 93795ad..30af996 100644 (file)
@@ -96,8 +96,8 @@ namespace zypp
   Target_Ptr ZYpp::target() const
   { return _pimpl->target(); }
 
-  void ZYpp::initTarget(const Pathname & root, bool commit_only)
-  { _pimpl->initTarget(root, commit_only); }
+  void ZYpp::initTarget(const Pathname & root)
+  { _pimpl->initTarget(root); }
 
   void ZYpp::finishTarget()
   { _pimpl->finishTarget(); }
index 91d1e1d..c078da3 100644 (file)
@@ -87,9 +87,8 @@ namespace zypp
 
     /**
      * \throws Exception
-     * if commit_only == true, just init, don't populate store or pool
      */
-    void initTarget(const Pathname & root, bool commit_only = false);
+    void initTarget(const Pathname & root);
 
     /**
      * \throws Exception
index 2f75bfb..2a76d5a 100644 (file)
@@ -24,6 +24,8 @@
 #include "zypp/Resolvable.h"
 #include "zypp/ResObject.h"
 #include "zypp/Package.h"
+#include "zypp/Pattern.h"
+#include "zypp/Selection.h"
 #include "zypp/Script.h"
 #include "zypp/Message.h"
 #include "zypp/Source.h"
@@ -77,10 +79,9 @@ namespace zypp
     // METHOD TYPE : Ctor
     //
     TargetImpl::TargetImpl(const Pathname & root_r)
-    : _root(root_r)
+    : _root(root_r), _storage_enabled(false)
     {
       _rpm.initDatabase(root_r);
-      _storage_enabled = false;
       MIL << "Initialized target on " << _root << endl;
     }
 
@@ -112,39 +113,71 @@ namespace zypp
       return _root;
     }
 
-    const ResStore & TargetImpl::resolvables()
+    void TargetImpl::loadKindResolvables( const Resolvable::Kind kind )
     {
-      _store.clear();
-      // RPM objects
-      std::list<Package::Ptr> packages = _rpm.getPackages();
-      for (std::list<Package::Ptr>::const_iterator it = packages.begin();
-           it != packages.end();
-           it++)
-      {
-        _store.insert(*it);
-      }
+      if ( _resstore_loaded[kind] )
+        return;
 
-      if ( isStorageEnabled() )
+      if ( kind == ResTraits<zypp::Package>::kind )
       {
-        // resolvables stored in the zypp storage database
-        std::list<ResObject::Ptr> resolvables = _storage.storedObjects();
-        for (std::list<ResObject::Ptr>::iterator it = resolvables.begin();
-            it != resolvables.end();
+           std::list<Package::Ptr> packages = _rpm.getPackages();
+          for (std::list<Package::Ptr>::const_iterator it = packages.begin();
+            it != packages.end();
             it++)
-        {
-          _store.insert(*it);
-        }
+          {
+            _store.insert(*it);
+          }
+          _resstore_loaded[kind] = true;
       }
       else
       {
-        WAR << "storage target not enabled" << std::endl;
+          if ( isStorageEnabled() )
+          {
+            // resolvables stored in the zypp storage database
+            std::list<ResObject::Ptr> resolvables = _storage.storedObjects(kind);
+            for (std::list<ResObject::Ptr>::iterator it = resolvables.begin();
+                it != resolvables.end();
+                it++)
+            {
+              _store.insert(*it);
+            }
+          }
+          else
+          {
+            WAR << "storage target not enabled" << std::endl;
+          }
+          _resstore_loaded[kind] = true;
+      } // end switch
+    }
+
+    ResStore TargetImpl::resolvablesByKind( const Resolvable::Kind kind )
+    {
+      ResStore tmp_store;
+      
+      // load all resolvables of Kind kind in internal store
+      loadKindResolvables(kind);
+
+      for (ResStore::const_iterator it = _store.begin(); it != _store.end(); ++it)
+      {
+        // insert them in the tmp store we will return
+        if ((*it)->kind() == kind) {
+          tmp_store.insert(*it);
+        }
       }
+      return tmp_store;
+    }
 
+    const ResStore & TargetImpl::resolvables()
+    {
+      loadKindResolvables( ResTraits<zypp::Patch>::kind );
+      loadKindResolvables( ResTraits<zypp::Selection>::kind );
+      loadKindResolvables( ResTraits<zypp::Pattern>::kind );
+      loadKindResolvables( ResTraits<zypp::Product>::kind );
+      loadKindResolvables( ResTraits<zypp::Language>::kind );
+      loadKindResolvables( ResTraits<zypp::Package>::kind );
       return _store;
     }
 
-
-
     ZYppCommitResult TargetImpl::commit( ResPool pool_r, const ZYppCommitPolicy & policy_rX )
     {
       // ----------------------------------------------------------------- //
index b92067e..8432cbc 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "zypp/base/ReferenceCounted.h"
 #include "zypp/base/NonCopyable.h"
+#include "zypp/base/DefaultFalseBool.h"
 #include "zypp/base/PtrTypes.h"
 #include "zypp/ResStore.h"
 #include "zypp/PoolItem.h"
@@ -82,6 +83,11 @@ namespace zypp
       /** All resolvables in the target. */
       const ResStore & resolvables();
 
+      /**
+        * resolvables of certain kind
+        */
+      ResStore resolvablesByKind( const Resolvable::Kind kind );
+
       /** The root set for this target */
       Pathname root() const;
 
@@ -135,6 +141,7 @@ namespace zypp
       Date timestamp() const;
       
     protected:
+      void loadKindResolvables( const Resolvable::Kind kind );
       /** All resolvables provided by the target. */
       ResStore _store;
       /** Path to the target */
@@ -144,6 +151,7 @@ namespace zypp
 #ifndef STORAGE_DISABLED
       zypp::storage::PersistentStorage _storage;
       bool _storage_enabled;
+      std::map< const Resolvable::Kind, DefaultFalseBool> _resstore_loaded;
 #endif
     private:
       /** Null implementation */
index c9a0e1e..d5961b2 100644 (file)
@@ -193,9 +193,9 @@ namespace zypp
       return _target;
      }
 
-    void ZYppImpl::initTarget(const Pathname & root, bool commit_only)
+    void ZYppImpl::initTarget(const Pathname & root)
     {
-      MIL << "initTarget( " << root << ", " << commit_only << ")" << endl;
+      MIL << "initTarget( " << root << endl;
       if (_target) {
        if (_target->root() == root) {
            MIL << "Repeated call to initTarget()" << endl;
@@ -204,11 +204,7 @@ namespace zypp
        removeInstalledResolvables( );
       }
       _target = new Target( root );
-      if (!commit_only)
-      {
-       _target->enableStorage( root );
-       addResolvables( _target->resolvables(), true );
-      }
+      _target->enableStorage( root );
     }
 
     void ZYppImpl::finishTarget()
index fa05031..741ac8d 100644 (file)
@@ -86,7 +86,7 @@ namespace zypp
        * \throws Exception
        * if commit_only == true, just init the target, dont populate store or pool
        */
-      void initTarget(const Pathname & root, bool commit_only = false);
+      void initTarget(const Pathname & root);
 
       /**
        * \throws Exception