From 3dc789cbca485da4dae7bad8d224ae7b4f6856d8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 13 Feb 2020 17:46:10 -0500 Subject: [PATCH] replace pinned.js with low-profile streaming implementation --- lib/commands/pin-rpc.js | 3 +-- scripts/check-account-deletion.js | 3 +-- scripts/evict-inactive.js | 4 ++-- scripts/tests/test-pins.js | 34 +++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 scripts/tests/test-pins.js diff --git a/lib/commands/pin-rpc.js b/lib/commands/pin-rpc.js index e490f713d..3fc339d00 100644 --- a/lib/commands/pin-rpc.js +++ b/lib/commands/pin-rpc.js @@ -9,7 +9,6 @@ const Nacl = require("tweetnacl/nacl-fast"); const Util = require("../common-util"); const nThen = require("nthen"); const Saferphore = require("saferphore"); -const Pinned = require('../../scripts/pinned'); //const escapeKeyCharacters = Util.escapeKeyCharacters; const unescapeKeyCharacters = Util.unescapeKeyCharacters; @@ -432,7 +431,7 @@ Pinning.getDeletedPads = function (Env, channels, cb) { // inform that the Pinning.loadChannelPins = function (Env) { - Pinned.load(function (err, data) { + Pins.list(function (err, data) { if (err) { Env.Log.error("LOAD_CHANNEL_PINS", err); diff --git a/scripts/check-account-deletion.js b/scripts/check-account-deletion.js index 0532e69ed..91020bde9 100644 --- a/scripts/check-account-deletion.js +++ b/scripts/check-account-deletion.js @@ -1,7 +1,6 @@ /* jshint esversion: 6, node: true */ const Fs = require('fs'); const nThen = require('nthen'); -const Pinned = require('./pinned'); const Nacl = require('tweetnacl/nacl-fast'); const Path = require('path'); const Pins = require('../lib/pins'); @@ -41,7 +40,7 @@ nThen((waitFor) => { pinned = Pins.calculateFromLog(content.toString('utf8'), f); })); }).nThen((waitFor) => { - Pinned.load(waitFor((err, d) => { + Pins.list(waitFor((err, d) => { data = Object.keys(d); }), { exclude: [edPublic + '.ndjson'] diff --git a/scripts/evict-inactive.js b/scripts/evict-inactive.js index f0e801909..e3419ffad 100644 --- a/scripts/evict-inactive.js +++ b/scripts/evict-inactive.js @@ -2,7 +2,7 @@ var nThen = require("nthen"); var Store = require("../storage/file"); var BlobStore = require("../storage/blob"); -var Pinned = require("./pinned"); +var Pins = require("../lib/pins"); var config = require("../lib/load-config"); // the administrator should have set an 'inactiveTime' in their config @@ -38,7 +38,7 @@ nThen(function (w) { store = _; })); // load the list of pinned files so you know which files // should not be archived or deleted - Pinned.load(w(function (err, _) { + Pins.list(w(function (err, _) { if (err) { w.abort(); return void console.error(err); diff --git a/scripts/tests/test-pins.js b/scripts/tests/test-pins.js new file mode 100644 index 000000000..8697d238b --- /dev/null +++ b/scripts/tests/test-pins.js @@ -0,0 +1,34 @@ +/*jshint esversion: 6 */ +const Pins = require("../../lib/pins"); + +var stats = { + users: 0, + lines: 0, + pinned: 0, + events: 0, +}; + +Pins.list(function (err, pinned) { + for (var id in pinned) { + console.log(id); + stats.pinned++; + } + console.log(stats); +}, { + pinPath: require("../../lib/load-config").pinPath +}); + +/* +function (ref, safeKey, pinned) { + stats.users++; + stats.lines += ref.index; + + Object.keys(ref.pins).forEach(function (id) { + if (!pinned[id]) { + pinned[id] = true; + stats.pinned++; + } + }); + //console.log("pin", stats.events++); + //console.log(ref, safeKey); +}*/