From e921a4bc7faeac44d31e6f7aa8315e2105839082 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Fri, 5 Jul 2024 13:08:51 -0400 Subject: [PATCH] Local API: Improve search debugging Use our own method in order to debug scopes, with a new getter for that property. --- chrome/content/zotero/xpcom/data/search.js | 3 +++ .../content/zotero/xpcom/server/server_localAPI.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index e7567abd60..921f9724d7 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -93,6 +93,9 @@ Zotero.defineProperty(Zotero.Search.prototype, 'synced', { Zotero.defineProperty(Zotero.Search.prototype, 'conditions', { get: function () { return this.getConditions(); } }); +Zotero.defineProperty(Zotero.Search.prototype, 'scope', { + get: function() { return this._scope; } +}); Zotero.defineProperty(Zotero.Search.prototype, '_canHaveParent', { value: false }); diff --git a/chrome/content/zotero/xpcom/server/server_localAPI.js b/chrome/content/zotero/xpcom/server/server_localAPI.js index e4ddd40b36..6a102bb2ec 100644 --- a/chrome/content/zotero/xpcom/server/server_localAPI.js +++ b/chrome/content/zotero/xpcom/server/server_localAPI.js @@ -661,7 +661,7 @@ Zotero.Server.LocalAPI.Items = class extends LocalAPIEndpoint { ); Zotero.debug('Executing local API search'); - Zotero.debug(search.toJSON()); + Zotero.debug(searchToDebugJSON(search)); // Searches sometimes return duplicate IDs; de-duplicate first // TODO: Fix in search.js let uniqueResultIDs = [...new Set(await search.search())]; @@ -1042,4 +1042,16 @@ function buildSearchFromSearchSyntax(parentSearch, searchStrings, condition) { return parentSearch; } +function searchToDebugJSON(search) { + return { + conditions: Object.values(search.conditions).map(condition => ({ + condition: condition.condition, + operator: condition.operator, + value: condition.value + })), + libraryID: search.libraryID, + scope: search.scope ? searchToDebugJSON(search.scope) : undefined + }; +} + class BadRequestError extends Error {}