- implement disk usage basic infrastructure for cache store
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 1 Aug 2007 13:15:43 +0000 (13:15 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 1 Aug 2007 13:15:43 +0000 (13:15 +0000)
- todo: retrieving it
- make changelog and filelist api similar to the other functions

zypp/cache/CacheInitializer.h
zypp/cache/CacheStore.cc
zypp/cache/CacheStore.h
zypp/cache/schema/schema.sql
zypp/data/ResolvableDataConsumer.h
zypp/parser/yum/RepoParser.cc

index 084e547..61a41ef 100644 (file)
@@ -19,7 +19,7 @@
 #include "zypp/Pathname.h"
 #include "zypp/cache/sqlite3x/sqlite3x.hpp"
 
-#define ZYPP_CACHE_SCHEMA_VERSION 1000
+#define ZYPP_CACHE_SCHEMA_VERSION 1001
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
index cedffdc..27cb0e6 100644 (file)
@@ -128,7 +128,11 @@ struct CacheStore::Impl
       "insert into patch_packages_baseversions (patch_package_id, version, release, epoch) "
       "values (:patch_package_id, :version, :release, :epoch)" ));
 
-
+    update_disk_usage_cmd.reset( new sqlite3_command (con,
+      "insert or replace into resolvable_disk_usage (resolvable_id, dir_name_id, files, size) "
+      "values (:resolvable_id, :dir_name_id, :files, :size)" ));
+    
+    
     // disable autocommit
     con.executenonquery("BEGIN;");
   }
@@ -190,6 +194,8 @@ struct CacheStore::Impl
   sqlite3_command_ptr insert_deltarpm_cmd;
   sqlite3_command_ptr append_patch_baseversion_cmd;
 
+  sqlite3_command_ptr update_disk_usage_cmd;
+  
   map<string, RecordId> name_cache;
   map< pair<string,string>, RecordId> type_cache;
   int name_cache_hits;
@@ -412,8 +418,7 @@ RecordId CacheStore::consumeProduct( const data::RecordId & repository_id,
   return id;
 }
 
-RecordId CacheStore::consumeChangelog( const data::RecordId & repository_id,
-                                   const data::Resolvable_Ptr & resolvable,
+RecordId CacheStore::consumeChangelog( const data::RecordId &resolvable_id,
                                    const Changelog & changelog )
 {
   //! \todo maybe appendChangelog(const data::RecordId & resolvable_id, Changelog changelog) will be needed
@@ -422,14 +427,37 @@ RecordId CacheStore::consumeChangelog( const data::RecordId & repository_id,
   return data::noRecordId;
 }
 
-RecordId CacheStore::consumeFilelist( const data::RecordId & repository_id,
-                                  const data::Resolvable_Ptr & resolvable,
+RecordId CacheStore::consumeFilelist( const data::RecordId &resolvable_id,
                                   const data::Filenames & filenames )
 {
   //! \todo maybe consumeFilelist(const data::RecordId & resolvable_id, data::Filenames &) will be needed
   return data::noRecordId;
 }
 
+void CacheStore::consumeDiskUsage( const data::RecordId &resolvable_id,
+                                  const DiskUsage &disk )
+{
+  // iterate over entries
+  for ( DiskUsage::const_iterator it = disk.begin();
+        it != disk.end();
+        ++it )
+  {
+    data::RecordId dirid = lookupOrAppendDirName( (*it).path );
+    try
+    {
+      _pimpl->update_disk_usage_cmd->bind(":resolvable_id", resolvable_id);
+      _pimpl->update_disk_usage_cmd->bind(":dir_name_id", dirid);
+      _pimpl->update_disk_usage_cmd->bind(":files", (int)(*it)._files );
+      _pimpl->update_disk_usage_cmd->bind(":size", (int)(*it)._size );
+      _pimpl->update_disk_usage_cmd->executenonquery();
+    }
+    catch ( const sqlite3x::database_error &e )
+    {
+      ZYPP_RETHROW(e);
+    }
+  }
+}
+
 void CacheStore::updatePackageLang( const data::RecordId & resolvable_id,
                                    const data::Packagebase_Ptr & data_r )
 {
index b940f94..447d914 100644 (file)
@@ -169,8 +169,7 @@ namespace zypp
        * \param changelog  the changelog
        * \todo see implementation
        */
-      virtual data::RecordId consumeChangelog( const data::RecordId & repository_id,
-                                              const data::Resolvable_Ptr & resolvable,
+      virtual data::RecordId consumeChangelog( const data::RecordId & resolvable_id,
                                               const Changelog & changelog );
 
       /**
@@ -182,9 +181,24 @@ namespace zypp
        * \param filenames  list of filenames the resolvable contains
        * \todo see implementation
        */
-      virtual data::RecordId consumeFilelist( const data::RecordId &repository_id,
-                                             const data::Resolvable_Ptr & resolvable,
+      virtual data::RecordId consumeFilelist( const data::RecordId & resolvable_id,
                                              const data::Filenames & filenames );
+      
+      /**
+       * Implementation of the \ref ResolvableDataConsumer interface
+       *
+       * Consume disk usage of a resolvable, inserting it in the cache.
+       *
+       * Repeated entries are updated (replaced)
+       *
+       * \param repository_id ownership.
+       * \param resolvable resolvable for which the filelist is to be saved
+       * \param disk  Disk usage object
+       * \todo see implementation
+       */
+       virtual void consumeDiskUsage( const data::RecordId &resolvable_id,
+                                      const DiskUsage &disk );
+
 
       /**
        * Implementation of the \ref ResolvableDataConsumer interface
index d0739e2..30a3a41 100644 (file)
@@ -258,7 +258,34 @@ CREATE TABLE split_capabilities (
 );
 CREATE INDEX split_capabilities_resolvable ON split_capabilities(resolvable_id);
 
--- Auto clean capabilities
+------------------------------------------------
+-- File list
+------------------------------------------------
+
+CREATE TABLE resolvable_files (
+    resolvable_id INTEGER REFERENCES resolvables (id)
+  , file_id INTEGER REFERENCES files (id)
+  , PRIMARY KEY ( resolvable_id, file_id )
+);
+
+------------------------------------------------
+-- Disk usage
+------------------------------------------------
+
+CREATE TABLE resolvable_disk_usage (
+    resolvable_id INTEGER REFERENCES resolvables (id)
+  , dir_name_id INTEGER REFERENCES dir_name (id)
+  , files INTEGER
+  , size INTEGER
+  , PRIMARY KEY ( resolvable_id, dir_name_id )
+);
+CREATE INDEX disk_usage_resolvable_id ON resolvable_disk_usage(resolvable_id);
+CREATE INDEX disk_usage_dir_name_id ON resolvable_disk_usage(dir_name_id);
+
+------------------------------------------------
+-- Cleanup
+------------------------------------------------
+
 CREATE TRIGGER remove_resolvables
   AFTER DELETE ON resolvables
   BEGIN
@@ -271,8 +298,13 @@ CREATE TRIGGER remove_resolvables
     
     DELETE FROM text_attributes  WHERE weak_resolvable_id = old.id;
     DELETE FROM numeric_attributes  WHERE weak_resolvable_id = old.id;
+    DELETE FROM resolvable_disk_usage WHERE resolvable_id = old.id;
+    DELETE FROM resolvable_files WHERE resolvable_id = old.id;
   END;
 
+
+
+
 ------------------------------------------------
 -- Associate resolvables and repositories
 ------------------------------------------------
index 5141db0..844af57 100644 (file)
@@ -11,6 +11,7 @@
 #define ZYPP_ResolvableDataConsumer_H
 
 
+#include "zypp/DiskUsage.h"
 #include "zypp/data/RecordId.h"
 #include "zypp/data/ResolvableData.h"
 
@@ -37,10 +38,12 @@ namespace data
     virtual data::RecordId consumeScript       ( const data::RecordId & repository_id, const data::Script_Ptr & ) = 0;
     virtual data::RecordId consumePattern      ( const data::RecordId & repository_id, const data::Pattern_Ptr & ) = 0;
 
-    virtual data::RecordId consumeChangelog    ( const data::RecordId & repository_id, const data::Resolvable_Ptr &, const Changelog & ) = 0;
-    virtual data::RecordId consumeFilelist     ( const data::RecordId & repository_id, const data::Resolvable_Ptr &, const data::Filenames & ) = 0;
-
+    virtual data::RecordId consumeChangelog    ( const data::RecordId & resolvable_id, const Changelog & ) = 0;
+    virtual data::RecordId consumeFilelist     ( const data::RecordId & resolvable_id, const data::Filenames & ) = 0;
+    virtual void consumeDiskUsage              ( const data::RecordId &resolvable_id, const DiskUsage &disk ) = 0;
+    
     virtual void updatePackageLang( const data::RecordId & resolvable_id, const data::Packagebase_Ptr & data_r ) = 0;
+    
   };
 
 } // namespace parser
index 82d76e5..e941413 100644 (file)
@@ -246,7 +246,7 @@ namespace zypp
   bool RepoParser::Impl::other_CB(
     const data::Resolvable_Ptr & res_ptr, const Changelog & changelog)
   {
-    _consumer.consumeChangelog(_repository_id, res_ptr, changelog);
+    //_consumer.consumeChangelog(_repository_id, res_ptr, changelog);
 /*
     DBG << "got changelog for "
       << res_ptr->name << res_ptr->edition << " "
@@ -263,7 +263,7 @@ namespace zypp
   bool RepoParser::Impl::filelist_CB(
     const data::Resolvable_Ptr & res_ptr, const data::Filenames & filenames)
   {
-    _consumer.consumeFilelist(_repository_id, res_ptr, filenames);
+    //_consumer.consumeFilelist(_repository_id, res_ptr, filenames);
 /*
     DBG << "got filelist for "
       << res_ptr->name << res_ptr->edition << " "