Improve initial state transfer locking

This commit is contained in:
Frank A. Krueger 2017-11-15 21:58:48 -06:00
parent 6ec5bbe5a3
commit d63d7e7ffc
1 changed files with 20 additions and 14 deletions

View File

@ -573,34 +573,40 @@ namespace Ooui
void QueueStateMessagesLocked (EventTarget target) void QueueStateMessagesLocked (EventTarget target)
{ {
if (target == null) return; if (target == null) return;
var created = false;
foreach (var m in target.StateMessages) { foreach (var m in target.StateMessages) {
if (m.MessageType == MessageType.Create) {
createdIds.Add (m.TargetId);
created = true;
}
if (created) {
QueueMessageLocked (m); QueueMessageLocked (m);
} }
} }
}
void QueueMessageLocked (Message message) void QueueMessageLocked (Message message)
{ {
// //
// Make sure all the referenced objects have been created // Make sure all the referenced objects have been created
// //
if (message.MessageType == MessageType.Create) {
createdIds.Add (message.TargetId);
}
else {
if (!createdIds.Contains (message.TargetId)) { if (!createdIds.Contains (message.TargetId)) {
createdIds.Add (message.TargetId);
QueueStateMessagesLocked (element.GetElementById (message.TargetId)); QueueStateMessagesLocked (element.GetElementById (message.TargetId));
} }
if (message.Value is Array a) { if (message.Value is EventTarget ve) {
if (!createdIds.Contains (ve.Id)) {
QueueStateMessagesLocked (ve);
}
}
else if (message.Value is Array a) {
for (var i = 0; i < a.Length; i++) { for (var i = 0; i < a.Length; i++) {
// Console.WriteLine ($"A{i} = {a.GetValue(i)}"); // Console.WriteLine ($"A{i} = {a.GetValue(i)}");
if (a.GetValue (i) is EventTarget e && !createdIds.Contains (e.Id)) { if (a.GetValue (i) is EventTarget e && !createdIds.Contains (e.Id)) {
createdIds.Add (e.Id);
QueueStateMessagesLocked (e); QueueStateMessagesLocked (e);
} }
} }
} }
}
// //
// Add it to the queue // Add it to the queue
// //