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

View File

@@ -9,7 +9,7 @@ use std::{
use rbx_tree::{RbxTree, RbxValue, RbxId}; use rbx_tree::{RbxTree, RbxValue, RbxId};
use crate::{ use crate::{
project::{Project, ProjectNode, InstanceProjectNode, InstanceProjectNodeConfig}, project::{Project, ProjectNode, InstanceProjectNode, InstanceProjectNodeMetadata},
message_queue::MessageQueue, message_queue::MessageQueue,
imfs::{Imfs, ImfsItem, ImfsFile}, imfs::{Imfs, ImfsItem, ImfsFile},
path_map::PathMap, path_map::PathMap,
@@ -19,7 +19,7 @@ use crate::{
pub struct RbxSession { pub struct RbxSession {
tree: RbxTree, tree: RbxTree,
path_map: PathMap<RbxId>, path_map: PathMap<RbxId>,
instance_metadata_map: HashMap<RbxId, InstanceProjectNodeConfig>, instance_metadata_map: HashMap<RbxId, InstanceProjectNodeMetadata>,
message_queue: Arc<MessageQueue<InstanceChanges>>, message_queue: Arc<MessageQueue<InstanceChanges>>,
imfs: Arc<Mutex<Imfs>>, imfs: Arc<Mutex<Imfs>>,
project: Arc<Project>, project: Arc<Project>,
@@ -128,7 +128,7 @@ impl RbxSession {
&self.tree &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 &self.instance_metadata_map
} }
} }
@@ -143,7 +143,7 @@ fn construct_initial_tree(
project: &Project, project: &Project,
imfs: &Imfs, imfs: &Imfs,
path_map: &mut PathMap<RbxId>, path_map: &mut PathMap<RbxId>,
instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>, instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
) -> RbxTree { ) -> RbxTree {
let snapshot = construct_project_node( let snapshot = construct_project_node(
imfs, imfs,
@@ -194,7 +194,7 @@ fn construct_instance_node<'a>(
properties: HashMap::new(), properties: HashMap::new(),
children, children,
source_path: None, 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, properties,
children: Vec::new(), children: Vec::new(),
source_path: Some(file.path.clone()), source_path: Some(file.path.clone()),
config: None, metadata: None,
}) })
}, },
ImfsItem::Directory(directory) => { ImfsItem::Directory(directory) => {
@@ -268,7 +268,7 @@ fn snapshot_instances_from_imfs<'a>(imfs: &'a Imfs, imfs_path: &Path) -> Option<
properties: HashMap::new(), properties: HashMap::new(),
children: Vec::new(), children: Vec::new(),
source_path: Some(directory.path.clone()), 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::{ use crate::{
path_map::PathMap, path_map::PathMap,
project::InstanceProjectNodeConfig, project::InstanceProjectNodeMetadata,
}; };
#[derive(Debug, Clone, Default, Serialize, Deserialize)] #[derive(Debug, Clone, Default, Serialize, Deserialize)]
@@ -31,13 +31,13 @@ pub struct RbxSnapshotInstance<'a> {
pub properties: HashMap<String, RbxValue>, pub properties: HashMap<String, RbxValue>,
pub children: Vec<RbxSnapshotInstance<'a>>, pub children: Vec<RbxSnapshotInstance<'a>>,
pub source_path: Option<PathBuf>, pub source_path: Option<PathBuf>,
pub config: Option<InstanceProjectNodeConfig>, pub metadata: Option<InstanceProjectNodeMetadata>,
} }
pub fn reify_root( pub fn reify_root(
snapshot: &RbxSnapshotInstance, snapshot: &RbxSnapshotInstance,
path_map: &mut PathMap<RbxId>, path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>, instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges, changes: &mut InstanceChanges,
) -> RbxTree { ) -> RbxTree {
let instance = reify_core(snapshot); let instance = reify_core(snapshot);
@@ -48,14 +48,14 @@ pub fn reify_root(
path_map.insert(source_path.clone(), root_id); path_map.insert(source_path.clone(), root_id);
} }
if let Some(config) = &snapshot.config { if let Some(metadata) = &snapshot.metadata {
config_map.insert(root_id, config.clone()); instance_metadata_map.insert(root_id, metadata.clone());
} }
changes.added.insert(root_id); changes.added.insert(root_id);
for child in &snapshot.children { 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 tree
@@ -66,7 +66,7 @@ pub fn reify_subtree(
tree: &mut RbxTree, tree: &mut RbxTree,
parent_id: RbxId, parent_id: RbxId,
path_map: &mut PathMap<RbxId>, path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>, instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges, changes: &mut InstanceChanges,
) { ) {
let instance = reify_core(snapshot); let instance = reify_core(snapshot);
@@ -76,14 +76,14 @@ pub fn reify_subtree(
path_map.insert(source_path.clone(), id); path_map.insert(source_path.clone(), id);
} }
if let Some(config) = &snapshot.config { if let Some(metadata) = &snapshot.metadata {
config_map.insert(id, config.clone()); instance_metadata_map.insert(id, metadata.clone());
} }
changes.added.insert(id); changes.added.insert(id);
for child in &snapshot.children { 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, id: RbxId,
snapshot: &RbxSnapshotInstance, snapshot: &RbxSnapshotInstance,
path_map: &mut PathMap<RbxId>, path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>, instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges, changes: &mut InstanceChanges,
) { ) {
if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) { if reconcile_instance_properties(tree.get_instance_mut(id).unwrap(), snapshot) {
changes.updated.insert(id); 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 { fn reify_core(snapshot: &RbxSnapshotInstance) -> RbxInstance {
@@ -180,7 +180,7 @@ fn reconcile_instance_children(
id: RbxId, id: RbxId,
snapshot: &RbxSnapshotInstance, snapshot: &RbxSnapshotInstance,
path_map: &mut PathMap<RbxId>, path_map: &mut PathMap<RbxId>,
config_map: &mut HashMap<RbxId, InstanceProjectNodeConfig>, instance_metadata_map: &mut HashMap<RbxId, InstanceProjectNodeMetadata>,
changes: &mut InstanceChanges, changes: &mut InstanceChanges,
) { ) {
let children_ids = tree.get_instance(id).unwrap().get_children_ids().to_vec(); 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 { 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 { for child_id in &children_to_remove {
if let Some(subtree) = tree.remove_instance(*child_id) { if let Some(subtree) = tree.remove_instance(*child_id) {
for id in subtree.iter_all_ids() { for id in subtree.iter_all_ids() {
config_map.remove(&id); instance_metadata_map.remove(&id);
changes.removed.insert(id); changes.removed.insert(id);
} }
} }
} }
for (child_id, child_snapshot) in &children_to_update { 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::{ use crate::{
session::Session, session::Session,
session_id::SessionId, session_id::SessionId,
project::InstanceProjectNodeConfig, project::InstanceProjectNodeMetadata,
rbx_snapshot::InstanceChanges, rbx_snapshot::InstanceChanges,
}; };
@@ -26,7 +26,7 @@ pub struct ServerInfoResponse<'a> {
pub server_version: &'a str, pub server_version: &'a str,
pub protocol_version: u64, pub protocol_version: u64,
pub root_instance_id: RbxId, 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)] #[derive(Debug, Serialize, Deserialize)]

View File

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