mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
Implement sync source-only mode in ServeSession and ChangeBatcher
- Added support for a new sync mode in ServeSession that filters property changes to only include the Source property when the server indicates it is in source-only mode. - Updated ChangeBatcher to handle the new syncSourceOnly parameter, ensuring that only relevant property changes are processed based on the server's capabilities. - Enhanced API response to include sync_source_only flag, indicating the server's sync capabilities. - Adjusted related functions to accommodate the new sync logic, improving data synchronization efficiency.
This commit is contained in:
parent
8650cdbd82
commit
b30aa8280d
6 changed files with 52 additions and 8 deletions
|
|
@ -106,13 +106,17 @@ function App:init()
|
||||||
-- Our notif is now out of date- redoing will not restore the patch
|
-- Our notif is now out of date- redoing will not restore the patch
|
||||||
-- since we've undone even further. Dismiss the notif.
|
-- since we've undone even further. Dismiss the notif.
|
||||||
cleanup()
|
cleanup()
|
||||||
dismissNotif()
|
if dismissNotif then
|
||||||
|
dismissNotif()
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
redoConnection = ChangeHistoryService.OnRedo:Once(function(redoneAction: string)
|
redoConnection = ChangeHistoryService.OnRedo:Once(function(redoneAction: string)
|
||||||
if redoneAction == action then
|
if redoneAction == action then
|
||||||
-- The user has restored the patch, so we can dismiss the notif
|
-- The user has restored the patch, so we can dismiss the notif
|
||||||
cleanup()
|
cleanup()
|
||||||
dismissNotif()
|
if dismissNotif then
|
||||||
|
dismissNotif()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ local PatchSet = require(script.Parent.Parent.PatchSet)
|
||||||
|
|
||||||
local encodePatchUpdate = require(script.Parent.encodePatchUpdate)
|
local encodePatchUpdate = require(script.Parent.encodePatchUpdate)
|
||||||
|
|
||||||
return function(instanceMap, propertyChanges)
|
return function(instanceMap, propertyChanges, syncSourceOnly)
|
||||||
local patch = PatchSet.newEmpty()
|
local patch = PatchSet.newEmpty()
|
||||||
|
|
||||||
for instance, properties in propertyChanges do
|
for instance, properties in propertyChanges do
|
||||||
|
|
@ -30,8 +30,20 @@ return function(instanceMap, propertyChanges)
|
||||||
Log.warn("Cannot sync non-nil Parent property changes yet")
|
Log.warn("Cannot sync non-nil Parent property changes yet")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local update = encodePatchUpdate(instance, instanceId, properties)
|
if syncSourceOnly then
|
||||||
table.insert(patch.updated, update)
|
-- Filter to only Source property when server is in source-only mode
|
||||||
|
if properties.Source then
|
||||||
|
local update = encodePatchUpdate(instance, instanceId, { Source = true })
|
||||||
|
if update then
|
||||||
|
table.insert(patch.updated, update)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local update = encodePatchUpdate(instance, instanceId, properties)
|
||||||
|
if update then
|
||||||
|
table.insert(patch.updated, update)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
propertyChanges[instance] = nil
|
propertyChanges[instance] = nil
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,16 @@ function ChangeBatcher.new(instanceMap, onChangesFlushed)
|
||||||
__instanceMap = instanceMap,
|
__instanceMap = instanceMap,
|
||||||
__onChangesFlushed = onChangesFlushed,
|
__onChangesFlushed = onChangesFlushed,
|
||||||
__pendingPropertyChanges = {},
|
__pendingPropertyChanges = {},
|
||||||
|
__syncSourceOnly = false,
|
||||||
}, ChangeBatcher)
|
}, ChangeBatcher)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ChangeBatcher:setSyncSourceOnly(enabled)
|
||||||
|
self.__syncSourceOnly = enabled
|
||||||
|
end
|
||||||
|
|
||||||
function ChangeBatcher:stop()
|
function ChangeBatcher:stop()
|
||||||
self.__renderSteppedConnection:Disconnect()
|
self.__renderSteppedConnection:Disconnect()
|
||||||
self.__pendingPropertyChanges = {}
|
self.__pendingPropertyChanges = {}
|
||||||
|
|
@ -69,7 +74,7 @@ function ChangeBatcher:__flush()
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local patch = createPatchSet(self.__instanceMap, self.__pendingPropertyChanges)
|
local patch = createPatchSet(self.__instanceMap, self.__pendingPropertyChanges, self.__syncSourceOnly)
|
||||||
|
|
||||||
if PatchSet.isEmpty(patch) then
|
if PatchSet.isEmpty(patch) then
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@ function ServeSession.new(options)
|
||||||
__status = Status.NotStarted,
|
__status = Status.NotStarted,
|
||||||
__apiContext = options.apiContext,
|
__apiContext = options.apiContext,
|
||||||
__twoWaySync = options.twoWaySync,
|
__twoWaySync = options.twoWaySync,
|
||||||
|
__syncSourceOnly = false,
|
||||||
__reconciler = reconciler,
|
__reconciler = reconciler,
|
||||||
__instanceMap = instanceMap,
|
__instanceMap = instanceMap,
|
||||||
__changeBatcher = changeBatcher,
|
__changeBatcher = changeBatcher,
|
||||||
|
|
@ -196,6 +197,11 @@ function ServeSession:start()
|
||||||
:connect()
|
:connect()
|
||||||
:andThen(function(serverInfo)
|
:andThen(function(serverInfo)
|
||||||
self:setLoadingText("Loading initial data from server...")
|
self:setLoadingText("Loading initial data from server...")
|
||||||
|
|
||||||
|
-- Configure sync mode based on server capabilities
|
||||||
|
self.__syncSourceOnly = serverInfo.syncSourceOnly or false
|
||||||
|
self.__changeBatcher:setSyncSourceOnly(self.__syncSourceOnly)
|
||||||
|
|
||||||
return self:__initialSync(serverInfo):andThen(function()
|
return self:__initialSync(serverInfo):andThen(function()
|
||||||
self:setLoadingText("Starting sync loop...")
|
self:setLoadingText("Starting sync loop...")
|
||||||
self:__setStatus(Status.Connected, serverInfo.projectName)
|
self:__setStatus(Status.Connected, serverInfo.projectName)
|
||||||
|
|
@ -526,8 +532,20 @@ function ServeSession:__initialSync(serverInfo)
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|
||||||
local update = encodePatchUpdate(instance, change.id, change.changedProperties)
|
local propertiesToSync = change.changedProperties
|
||||||
table.insert(inversePatch.updated, update)
|
if self.__syncSourceOnly then
|
||||||
|
-- Filter to only Source property when server is in source-only mode
|
||||||
|
if propertiesToSync.Source then
|
||||||
|
propertiesToSync = { Source = propertiesToSync.Source }
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local update = encodePatchUpdate(instance, change.id, propertiesToSync)
|
||||||
|
if update then
|
||||||
|
table.insert(inversePatch.updated, update)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-- Add the removed instances back to Rojo
|
-- Add the removed instances back to Rojo
|
||||||
-- selene:allow(empty_if, unused_variable, empty_loop)
|
-- selene:allow(empty_if, unused_variable, empty_loop)
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ impl ApiService {
|
||||||
place_id: self.serve_session.place_id(),
|
place_id: self.serve_session.place_id(),
|
||||||
game_id: self.serve_session.game_id(),
|
game_id: self.serve_session.game_id(),
|
||||||
root_instance_id,
|
root_instance_id,
|
||||||
|
sync_source_only: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,10 @@ pub struct ServerInfoResponse {
|
||||||
pub game_id: Option<u64>,
|
pub game_id: Option<u64>,
|
||||||
pub place_id: Option<u64>,
|
pub place_id: Option<u64>,
|
||||||
pub root_instance_id: Ref,
|
pub root_instance_id: Ref,
|
||||||
|
/// When true, the server only supports syncing script Source property changes.
|
||||||
|
/// Other property changes will be ignored.
|
||||||
|
#[serde(default)]
|
||||||
|
pub sync_source_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Response body from /api/read/{id}
|
/// Response body from /api/read/{id}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue