mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: only dereference id if it doesn't exist locally — fewer calls
This commit is contained in:
@@ -22,21 +22,33 @@ Notes.assert = async (uid, input, options = {}) => {
|
|||||||
const actors = new Set();
|
const actors = new Set();
|
||||||
|
|
||||||
await Promise.all(input.map(async (item) => {
|
await Promise.all(input.map(async (item) => {
|
||||||
// Dereference only if a url is received
|
let id = activitypub.helpers.isUri(item) ? item : item.pid;
|
||||||
if (activitypub.helpers.isUri(item)) {
|
let key = `post:${id}`;
|
||||||
item = await activitypub.resolveId(uid, item);
|
let exists = await db.exists(key);
|
||||||
if (!item) {
|
|
||||||
winston.warn(`[activitypub/notes.assert] Not asserting ${item}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = activitypub.helpers.isUri(item) ? item : item.pid;
|
|
||||||
const key = `post:${id}`;
|
|
||||||
const exists = await db.exists(key);
|
|
||||||
winston.verbose(`[activitypub/notes.assert] Asserting note id ${id}`);
|
winston.verbose(`[activitypub/notes.assert] Asserting note id ${id}`);
|
||||||
|
|
||||||
if (id && (!exists || options.update === true)) {
|
if (id && (!exists || options.update === true)) {
|
||||||
|
// Dereference only if a url is received
|
||||||
|
if (activitypub.helpers.isUri(item)) {
|
||||||
|
winston.verbose(`[activitypub/notes.assert] Dereference check for ${id}`);
|
||||||
|
const resolvedId = await activitypub.resolveId(uid, item);
|
||||||
|
if (!resolvedId) {
|
||||||
|
winston.warn(`[activitypub/notes.assert] Not asserting ${item}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resolvedId !== id) {
|
||||||
|
id = resolvedId;
|
||||||
|
key = `post:${id}`;
|
||||||
|
exists = await db.exists(key);
|
||||||
|
winston.verbose(`[activitypub/notes.assert] Re-asserting note id ${id}`);
|
||||||
|
|
||||||
|
if (exists && options.update !== true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let postData;
|
let postData;
|
||||||
winston.verbose(`[activitypub/notes.assert] Not found, retrieving note for persistence...`);
|
winston.verbose(`[activitypub/notes.assert] Not found, retrieving note for persistence...`);
|
||||||
if (activitypub.helpers.isUri(item)) {
|
if (activitypub.helpers.isUri(item)) {
|
||||||
|
|||||||
@@ -187,7 +187,6 @@ module.exports = function (Topics) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parentPids = _.uniq(parentPids);
|
parentPids = _.uniq(parentPids);
|
||||||
await activitypub.notes.assert(uid, parentPids.filter(pid => activitypub.helpers.isUri(pid)));
|
|
||||||
const parentPosts = await posts.getPostsFields(parentPids, ['uid']);
|
const parentPosts = await posts.getPostsFields(parentPids, ['uid']);
|
||||||
const parentUids = _.uniq(parentPosts.map(postObj => postObj && postObj.uid));
|
const parentUids = _.uniq(parentPosts.map(postObj => postObj && postObj.uid));
|
||||||
const userData = await user.getUsersFields(parentUids, ['username']);
|
const userData = await user.getUsersFields(parentUids, ['username']);
|
||||||
|
|||||||
Reference in New Issue
Block a user