From 094192a86984d4018b209668d9b8dd547a3db1a8 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Fri, 5 Jun 2015 13:13:08 -0700 Subject: [PATCH] don't validate when we only need an updated column mapping --- object_store.cpp | 19 +++++++++++++++---- object_store.hpp | 11 ++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/object_store.cpp b/object_store.cpp index 9ecf0b5c..fd20858a 100644 --- a/object_store.cpp +++ b/object_store.cpp @@ -20,6 +20,7 @@ #include #include +#include using namespace realm; using namespace std; @@ -127,7 +128,7 @@ realm::TableRef ObjectStore::table_for_object_type_create_if_needed(realm::Group return group->get_or_add_table(table_name_for_object_type(object_type), &created); } -std::vector ObjectStore::validate_schema_and_update_column_mapping(realm::Group *group, ObjectSchema &target_schema) { +std::vector ObjectStore::validate_schema(realm::Group *group, ObjectSchema &target_schema) { vector validation_errors; ObjectSchema table_schema(group, target_schema.name); @@ -176,6 +177,16 @@ std::vector ObjectStore::validate_schema_and_update_column_mapping( return validation_errors; } +void ObjectStore::update_column_mapping(Group *group, ObjectSchema &target_schema) { + ObjectSchema table_schema(group, target_schema.name); + for (auto& target_prop:target_schema.properties) { + auto table_prop = table_schema.property_for_name(target_prop.name); + REALM_ASSERT_DEBUG(table_prop); + + target_prop.table_column = table_prop->table_column; + } +} + static inline bool property_has_changed(Property &p1, Property &p2) { return p1.type != p2.type || p1.name != p2.name || p1.object_type != p2.object_type; } @@ -283,7 +294,7 @@ bool ObjectStore::update_realm_with_schema(realm::Group *group, // read-only realms may be missing tables entirely if (table) { - auto errors = validate_schema_and_update_column_mapping(group, target_schema); + auto errors = validate_schema(group, target_schema); if (errors.size()) { throw ObjectStoreValidationException(errors, target_schema.name); } @@ -324,8 +335,8 @@ bool ObjectStore::indexes_are_up_to_date(Group *group, Schema &schema) { if (!table) { continue; } - - validate_schema_and_update_column_mapping(group, object_schema); // FIXME we just need the column mapping + + update_column_mapping(group, object_schema); for (auto& property:object_schema.properties) { if (property.requires_index() != table->has_search_index(property.table_column)) { return false; diff --git a/object_store.hpp b/object_store.hpp index f190d501..f342d4a9 100644 --- a/object_store.hpp +++ b/object_store.hpp @@ -35,8 +35,12 @@ namespace realm { static bool is_migration_required(realm::Group *group, uint64_t new_version); // verify a target schema against its table, setting the table_column property on each schema object + // updates the column mapping on the target_schema // returns array of validation errors - static std::vector validate_schema_and_update_column_mapping(Group *group, ObjectSchema &target_schema); + static std::vector validate_schema(Group *group, ObjectSchema &target_schema); + + // updates the target_column member for all properties based on the column indexes in the passed in group + static void update_column_mapping(Group *group, ObjectSchema &target_schema); // updates a Realm to a given target schema/version creating tables and updating indexes as necessary // returns if any changes were made @@ -45,10 +49,7 @@ namespace realm { // NOTE: must be performed within a write transaction typedef std::function MigrationFunction; typedef std::vector Schema; - static bool update_realm_with_schema(Group *group, - uint64_t version, - Schema &schema, - MigrationFunction migration); + static bool update_realm_with_schema(Group *group, uint64_t version, Schema &schema, MigrationFunction migration); // get a table for an object type static realm::TableRef table_for_object_type(Group *group, StringData object_type);