Fininsh config -> metadata migration

This commit is contained in:
Lucien Greathouse
2019-01-01 15:59:26 -08:00
parent 3be5988083
commit 20e9688268
5 changed files with 38 additions and 28 deletions

View File

@@ -51,7 +51,7 @@ impl SourceProjectNode {
class_name,
children: new_children,
properties,
config: InstanceProjectNodeConfig {
metadata: InstanceProjectNodeMetadata {
ignore_unknown,
},
})
@@ -131,10 +131,18 @@ pub struct ProjectSaveError;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InstanceProjectNodeConfig {
pub struct InstanceProjectNodeMetadata {
pub ignore_unknown: bool,
}
impl Default for InstanceProjectNodeMetadata {
fn default() -> InstanceProjectNodeMetadata {
InstanceProjectNodeMetadata {
ignore_unknown: true,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ProjectNode {
@@ -148,7 +156,7 @@ pub struct InstanceProjectNode {
pub class_name: String,
pub children: HashMap<String, ProjectNode>,
pub properties: HashMap<String, RbxValue>,
pub config: InstanceProjectNodeConfig,
pub metadata: InstanceProjectNodeMetadata,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

View File

@@ -9,7 +9,7 @@ use std::{
use rbx_tree::{RbxTree, RbxValue, RbxId};
use crate::{
project::{Project, ProjectNode, InstanceProjectNode, InstanceProjectNodeConfig},
project::{Project, ProjectNode, InstanceProjectNode, InstanceProjectNodeMetadata},
message_queue::MessageQueue,
imfs::{Imfs, ImfsItem, ImfsFile},
path_map::PathMap,
@@ -19,7 +19,7 @@ use crate::{
pub struct RbxSession {
tree: RbxTree,
path_map: PathMap<RbxId>,
instance_metadata_map: HashMap<RbxId, InstanceProjectNodeConfig>,
instance_metadata_map: HashMap<RbxId, InstanceProjectNodeMetadata>,
message_queue: Arc<MessageQueue<InstanceChanges>>,
imfs: Arc<Mutex<Imfs>>,
project: Arc<Project>,
@@ -128,7 +128,7 @@ impl RbxSession {
&self.tree
}
pub fn get_instance_metadata_map(&self) -> &HashMap<RbxId, InstanceProjectNodeConfig> {
pub fn get_instance_metadata_map(&self) -> &HashMap<RbxId, InstanceProjectNodeMetadata> {
&self.instance_metadata_map
}
}
@@ -143,7 +143,7 @@ fn construct_initial_tree(
project: &Project,
imfs: &Imfs,
path_map: &mut PathMap<RbxId>,
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
) -> RbxTree {
let snapshot = construct_project_node(
imfs,
@@ -194,7 +194,7 @@ fn construct_instance_node<'a>(
properties: HashMap::new(),
children,
source_path: None,
config: Some(project_node.config.clone()),
metadata: Some(project_node.metadata.clone()),
}
}
@@ -253,7 +253,7 @@ fn snapshot_instances_from_imfs<'a>(imfs: &'a Imfs, imfs_path: &Path) -> Option<
properties,
children: Vec::new(),
source_path: Some(file.path.clone()),
config: None,
metadata: None,
})
},
ImfsItem::Directory(directory) => {
@@ -268,7 +268,7 @@ fn snapshot_instances_from_imfs<'a>(imfs: &'a Imfs, imfs_path: &Path) -> Option<
properties: HashMap::new(),
children: Vec::new(),
source_path: Some(directory.path.clone()),
config: None,
metadata: None,
}
};

View File

@@ -9,7 +9,7 @@ use rbx_tree::{RbxTree, RbxId, RbxInstance, RbxValue};
use crate::{
path_map::PathMap,
project::InstanceProjectNodeConfig,
project::InstanceProjectNodeMetadata,
};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
@@ -31,13 +31,13 @@ pub struct RbxSnapshotInstance<'a> {
pub properties: HashMap<String, RbxValue>,
pub children: Vec<RbxSnapshotInstance<'a>>,
pub source_path: Option<PathBuf>,
pub config: Option<InstanceProjectNodeConfig>,
pub metadata: Option<InstanceProjectNodeMetadata>,
}
pub fn reify_root(
snapshot: &RbxSnapshotInstance,
path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges,
) -> RbxTree {
let instance = reify_core(snapshot);
@@ -48,14 +48,14 @@ pub fn reify_root(
path_map.insert(source_path.clone(), root_id);
}
if let Some(config) = &snapshot.config {
config_map.insert(root_id, config.clone());
if let Some(metadata) = &snapshot.metadata {
instance_metadata_map.insert(root_id, metadata.clone());
}
changes.added.insert(root_id);
for child in &snapshot.children {
reify_subtree(child, &mut tree, root_id, path_map, config_map, changes);
reify_subtree(child, &mut tree, root_id, path_map, instance_metadata_map, changes);
}
tree
@@ -66,7 +66,7 @@ pub fn reify_subtree(
tree: &mut RbxTree,
parent_id: RbxId,
path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges,
) {
let instance = reify_core(snapshot);
@@ -76,14 +76,14 @@ pub fn reify_subtree(
path_map.insert(source_path.clone(), id);
}
if let Some(config) = &snapshot.config {
config_map.insert(id, config.clone());
if let Some(metadata) = &snapshot.metadata {
instance_metadata_map.insert(id, metadata.clone());
}
changes.added.insert(id);
for child in &snapshot.children {
reify_subtree(child, tree, id, path_map, config_map, changes);
reify_subtree(child, tree, id, path_map, instance_metadata_map, changes);
}
}
@@ -92,14 +92,14 @@ pub fn reconcile_subtree(
id: RbxId,
snapshot: &RbxSnapshotInstance,
path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges,
) {
if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) {
changes.updated.insert(id);
}
reconcile_instance_children(tree, id, snapshot, path_map, config_map, changes);
reconcile_instance_children(tree, id, snapshot, path_map, instance_metadata_map, changes);
}
fn reify_core(snapshot: &RbxSnapshotInstance) -> RbxInstance {
@@ -180,7 +180,7 @@ fn reconcile_instance_children(
id: RbxId,
snapshot: &RbxSnapshotInstance,
path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>,
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges,
) {
let children_ids = tree.get_instance(id).unwrap().get_children_ids().to_vec();
@@ -211,19 +211,19 @@ fn reconcile_instance_children(
}
for child_snapshot in &children_to_add {
reify_subtree(child_snapshot, tree, id, path_map, config_map, changes);
reify_subtree(child_snapshot, tree, id, path_map, instance_metadata_map, changes);
}
for child_id in &children_to_remove {
if let Some(subtree) = tree.remove_instance(*child_id) {
for id in subtree.iter_all_ids() {
config_map.remove(&id);
instance_metadata_map.remove(&id);
changes.removed.insert(id);
}
}
}
for (child_id, child_snapshot) in &children_to_update {
reconcile_subtree(tree, *child_id, child_snapshot, path_map, config_map, changes);
reconcile_subtree(tree, *child_id, child_snapshot, path_map, instance_metadata_map, changes);
}
}

View File

@@ -15,7 +15,7 @@ use rbx_tree::{RbxId, RootedRbxInstance};
use crate::{
session::Session,
session_id::SessionId,
project::InstanceProjectNodeConfig,
project::InstanceProjectNodeMetadata,
rbx_snapshot::InstanceChanges,
};
@@ -26,7 +26,7 @@ pub struct ServerInfoResponse<'a> {
pub server_version: &'a str,
pub protocol_version: u64,
pub root_instance_id: RbxId,
pub instance_metadata_map: Cow<'a, HashMap<RbxId, InstanceProjectNodeConfig>>,
pub instance_metadata_map: Cow<'a, HashMap<RbxId, InstanceProjectNodeMetadata>>,
}
#[derive(Debug, Serialize, Deserialize)]

View File

@@ -66,6 +66,7 @@ fn single_sync_point() {
class_name: "ReplicatedStorage".to_string(),
children: replicated_storage_children,
properties: HashMap::new(),
metadata: Default::default(),
});
let mut root_children = HashMap::new();
@@ -75,6 +76,7 @@ fn single_sync_point() {
class_name: "DataModel".to_string(),
children: root_children,
properties: HashMap::new(),
metadata: Default::default(),
});
Project {