Comparison

plugins/mod_pubsub/pubsub.lib.lua @ 8300:7759eb130938

mod_pep_plus, mod_pubsub: Store node content in separate archive stores
author Kim Alvefur <zash@zash.se>
date Sun, 08 Oct 2017 01:56:44 +0200
parent 8298:dd9fa511494a
child 8301:e2ab440a3437
comparison
equal deleted inserted replaced
8299:756a2a00e7e7 8300:7759eb130938
329 local function simple_itemstore(archive, config, user, node, expose_publisher) 329 local function simple_itemstore(archive, config, user, node, expose_publisher)
330 module:log("debug", "Creation of itemstore for node %s with config %s", node, config); 330 module:log("debug", "Creation of itemstore for node %s with config %s", node, config);
331 local get_set = {}; 331 local get_set = {};
332 function get_set:items() 332 function get_set:items()
333 local store = self.store; 333 local store = self.store;
334 local data, err = archive:find(user, { with = node }); 334 local data, err = archive:find(user);
335 if not data then 335 if not data then
336 module:log("error", "Unable to get items: %s", err); 336 module:log("error", "Unable to get items: %s", err);
337 return true; 337 return true;
338 end 338 end
339 module:log("debug", "Listed items %s from store %s", data, store); 339 module:log("debug", "Listed items %s from store %s", data, store);
347 end; 347 end;
348 end 348 end
349 function get_set:get(key) 349 function get_set:get(key)
350 local store = self.store; 350 local store = self.store;
351 local data, err = archive:find(user, { 351 local data, err = archive:find(user, {
352 with = node;
353 key = key; 352 key = key;
354 }); 353 });
355 if not data then 354 if not data then
356 module:log("error", "Unable to get item: %s", err); 355 module:log("error", "Unable to get item: %s", err);
357 return nil, err; 356 return nil, err;
368 module:log("debug", "Set item %s to %s for %s in store %s", key, value, node, store); 367 module:log("debug", "Set item %s to %s for %s in store %s", key, value, node, store);
369 local data, err; 368 local data, err;
370 if value ~= nil then 369 if value ~= nil then
371 local publisher = value.attr.publisher; 370 local publisher = value.attr.publisher;
372 local payload = value.tags[1]; 371 local payload = value.tags[1];
373 data, err = archive:append(user, key, payload, time_now(), node); 372 data, err = archive:append(user, key, payload, time_now(), publisher);
374 else 373 else
375 data, err = archive:delete(user, { 374 data, err = archive:delete(user, { key = key; });
376 key = key;
377 with = node;
378 });
379 end 375 end
380 if not data then 376 if not data then
381 module:log("error", "Unable to set item: %s", err); 377 module:log("error", "Unable to set item: %s", err);
382 return nil, err; 378 return nil, err;
383 end 379 end
384 return data; 380 return data;
385 end 381 end
386 function get_set:clear() 382 function get_set:clear()
387 return archive:delete(user, { with = node }); 383 return archive:delete(user);
388 end 384 end
389 return setmetatable(get_set, archive); 385 return setmetatable(get_set, archive);
390 end 386 end
391 _M.simple_itemstore = simple_itemstore; 387 _M.simple_itemstore = simple_itemstore;
392 388