More efficient syncing

Thank you @PotOfCoffee2Go I ended up taking some of your code from #8101 to get this up and running. There's still some stuff missing (like the tests!) but it gets things moving.
This commit is contained in:
Jeremy Ruston
2024-03-23 09:27:54 +00:00
parent 52f76380c7
commit 08649dd1eb
7 changed files with 156 additions and 51 deletions

View File

@@ -20,17 +20,14 @@ exports.handler = function(request,response,state) {
// Get the parameters
var recipe_name = $tw.utils.decodeURIComponentSafe(state.params[0]);
if(recipe_name) {
// Get the tiddlers in the recipe
var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name);
// Get a skinny version of each tiddler
var tiddlers = [];
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
var tiddlerInfo = $tw.mws.store.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
tiddlers.push(Object.assign({},tiddlerInfo.tiddler,{text: undefined}));
// Get the tiddlers in the recipe, optionally since the specified last known tiddler_id
var recipeTiddlers = $tw.mws.store.getRecipeTiddlers(recipe_name,{
last_known_tiddler_id: state.queryParameters.last_known_tiddler_id
});
var text = JSON.stringify(tiddlers);
state.sendResponse(200,{"Content-Type": "application/json"},text,"utf8");
return;
if(recipeTiddlers) {
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(recipeTiddlers),"utf8");
return;
}
}
// Fail if something went wrong
response.writeHead(404);

View File

@@ -77,6 +77,10 @@ exports.handler = function(request,response,state) {
title: "$:/config/multiwikiclient/recipe",
text: recipe_name
});
writeTiddler({
title: "$:/state/multiwikiclient/recipe/last_tiddler_id",
text: $tw.mws.store.getRecipeLastTiddlerId(recipe_name).toString()
});
response.write(template.substring(markerPos + marker.length))
// Finish response
response.end();