From d19e131248105a3639e7a03f41d023c38b77ec30 Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 14 May 2020 20:34:31 -0400 Subject: Prefer backlinks.read for /links --- lib/serve.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/serve.js b/lib/serve.js index 46b78e7..749e075 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1834,15 +1834,30 @@ Serve.prototype.type = function (path) { Serve.prototype.links = function (path) { var q = this.query var dest = path.substr(1) - var opts = { - dest: dest, - reverse: true, - values: true, - } - if (q.rel) opts.rel = q.rel + var sbot = this.app.sbot pull( - this.app.sbot.links(opts), + q.rel || q.author || !sbot.backlinks ? (q.type ? + pull.error(new Error('Unable to satisfy query')) : + sbot.links({ + source: q.author || undefined, + dest: dest, + reverse: true, + values: true, + rel: q.rel + })) : sbot.backlinks.read({ + reverse: true, + query: [ + {$filter: { + dest: dest, + value: q.type ? { + content: { + type: q.type + } + } : {} + }} + ] + }), this.renderThread(), this.wrapMessages(), this.wrapLinks(dest), -- cgit v1.2.3