aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-09-12 13:01:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-09-12 13:01:49 +0200
commita051c451c178152dc0b37bf955bf60022d226843 (patch)
treec7efcf5f5a62499c0a39c87bb6cb26690216d5f2 /odb
parent6d7abb297bf7a4dcef4f90b4dfb3d46b7977e526 (diff)
Optimize schema version access for default schema
Diffstat (limited to 'odb')
-rw-r--r--odb/database.cxx33
-rw-r--r--odb/database.hxx20
-rw-r--r--odb/database.ixx39
3 files changed, 58 insertions, 34 deletions
diff --git a/odb/database.cxx b/odb/database.cxx
index ad71b4f..c9692ba 100644
--- a/odb/database.cxx
+++ b/odb/database.cxx
@@ -4,6 +4,8 @@
#include <odb/database.hxx>
+using namespace std;
+
namespace odb
{
database::
@@ -17,4 +19,35 @@ namespace odb
connection_type& c (transaction::current ().connection ());
return c.execute (st, n);
}
+
+ const database::schema_version_info& database::
+ schema_version_migration_ (const string& name) const
+ {
+ schema_version_map::const_iterator i (schema_version_map_.find (name));
+ const schema_version_info& svi (
+ i != schema_version_map_.end () && i->second.version != 0
+ ? i->second
+ : load_schema_version (name));
+
+ if (default_schema_version_ == 0 && name.empty ())
+ default_schema_version_ = &svi;
+
+ return svi;
+ }
+
+ void database::
+ schema_version_migration (const schema_version_migration_type& svm,
+ const string& name)
+ {
+ schema_version_info& svi (schema_version_map_[name]);
+ if (svi.version != svm.version || svi.migration != svm.migration)
+ {
+ svi.version = svm.version;
+ svi.migration = svm.migration;
+ schema_version_seq_++;
+ }
+
+ if (default_schema_version_ == 0 && name.empty ())
+ default_schema_version_ = &svi;
+ }
}
diff --git a/odb/database.hxx b/odb/database.hxx
index c7c4598..7ddbecb 100644
--- a/odb/database.hxx
+++ b/odb/database.hxx
@@ -339,24 +339,29 @@ namespace odb
typedef odb::schema_version_migration schema_version_migration_type;
schema_version_type
- schema_version (const std::string& schema_name = "") const;
+ schema_version (const std::string& schema_name = std::string ()) const;
bool
- schema_migration (const std::string& schema_name = "") const;
+ schema_migration (const std::string& schema_name = std::string ()) const;
+ // Note that there is code that relies on the returned reference
+ // being valid until the version is changed or the database instance
+ // is destroyed.
+ //
const schema_version_migration_type&
- schema_version_migration (const std::string& schema_name = "") const;
+ schema_version_migration (
+ const std::string& schema_name = std::string ()) const;
// Set schema version and migration state manually.
//
void
schema_version_migration (schema_version_type,
bool migration,
- const std::string& schema_name = "");
+ const std::string& schema_name = std::string ());
void
schema_version_migration (const schema_version_migration_type&,
- const std::string& schema_name = "");
+ const std::string& schema_name = std::string ());
// Set default schema version table for all schema names. The table
// name should already be quoted if necessary.
@@ -386,6 +391,10 @@ namespace odb
virtual const schema_version_info&
load_schema_version (const std::string& schema_name) const = 0;
+ private:
+ const schema_version_info&
+ schema_version_migration_ (const std::string& schema_name) const;
+
// Database id.
//
public:
@@ -478,6 +487,7 @@ namespace odb
std::string schema_version_table_;
mutable schema_version_map schema_version_map_;
+ mutable const schema_version_info* default_schema_version_; // Cached.
unsigned int schema_version_seq_;
};
}
diff --git a/odb/database.ixx b/odb/database.ixx
index 3de5bbc..378a376 100644
--- a/odb/database.ixx
+++ b/odb/database.ixx
@@ -11,7 +11,10 @@ namespace odb
{
inline database::
database (database_id id)
- : id_ (id), tracer_ (0), schema_version_seq_ (1)
+ : id_ (id),
+ tracer_ (0),
+ default_schema_version_ (0),
+ schema_version_seq_ (1)
{
}
@@ -36,14 +39,11 @@ namespace odb
inline const database::schema_version_migration_type& database::
schema_version_migration (const std::string& name) const
{
- // Note that there is code that relies on the returned reference
- // being valid until the version is changed or the database instance
- // is destroyed.
- //
- schema_version_map::const_iterator i (schema_version_map_.find (name));
- return i != schema_version_map_.end () && i->second.version != 0
- ? i->second
- : load_schema_version (name);
+ return name.empty () &&
+ default_schema_version_ != 0 &&
+ default_schema_version_->version != 0
+ ? *default_schema_version_
+ : schema_version_migration_ (name);
}
inline void database::
@@ -51,26 +51,7 @@ namespace odb
bool m,
const std::string& name)
{
- schema_version_info& svi (schema_version_map_[name]);
- if (svi.version != v || svi.migration != m)
- {
- svi.version = v;
- svi.migration = m;
- schema_version_seq_++;
- }
- }
-
- inline void database::
- schema_version_migration (const schema_version_migration_type& svm,
- const std::string& name)
- {
- schema_version_info& svi (schema_version_map_[name]);
- if (svi.version != svm.version || svi.migration != svm.migration)
- {
- svi.version = svm.version;
- svi.migration = svm.migration;
- schema_version_seq_++;
- }
+ schema_version_migration (schema_version_migration_type (v, m), name);
}
inline void database::