use /api/v1/statuses/ for status lookup instead of search

Pleroma search is terrible.
Even with resolve=true and passing a direct URL,
it will still attempt a fulltext search in addition to a URL fetch.
On most instances, search is so slow that simply opening a thread in Sengi would take several seconds.
As the search API is intended for "cold" lookups only, we switch to the status lookup endpoint.

This works on both Pleroma and Mastodon.
This commit is contained in:
io 2021-06-09 01:55:50 +00:00
parent 9426bc9e38
commit e1769f149e
3 changed files with 3 additions and 41 deletions

View File

@ -286,16 +286,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
let statusPromise: Promise<Status> = Promise.resolve(this.statusWrapper.status);
if (account.id !== this.statusWrapper.provider.id) {
statusPromise =
this.toolsService.getInstanceInfo(account)
.then(instance => {
let version: 'v1' | 'v2' = 'v1';
if (instance.major >= 3) version = 'v2';
return this.mastodonService.search(account, this.statusWrapper.status.url, version, true);
})
.then((result: Results) => {
return result.statuses[0];
});
statusPromise = this.mastodonService.getStatus(this.statusWrapper.status.id);
}
return statusPromise;

View File

@ -157,23 +157,8 @@ export class ThreadComponent extends BrowseBase {
if (status.visibility === 'public' || status.visibility === 'unlisted') {
// var statusPromise: Promise<Status> = Promise.resolve(status);
// if (!sourceAccount || sourceAccount.id !== currentAccount.id) {
var statusPromise = this.toolsService.getInstanceInfo(currentAccount)
.then(instance => {
let version: 'v1' | 'v2' = 'v1';
if (instance.major >= 3) version = 'v2';
return this.mastodonService.search(currentAccount, status.uri, version, true);
})
.then((result: Results) => {
if (result.statuses.length === 1) {
const retrievedStatus = result.statuses[0];
return retrievedStatus;
}
throw new Error('could not find status');
});
// }
var statusPromise = this.mastodonService.getStatus(currentAccount, status.id);
this.retrieveThread(currentAccount, statusPromise);
} else if (sourceAccount && sourceAccount.id === currentAccount.id) {
var statusPromise = Promise.resolve(status);
this.retrieveThread(currentAccount, statusPromise);

View File

@ -176,21 +176,7 @@ export class ToolsService {
if (!isProvider) {
statusPromise = statusPromise
.then((foreignStatus: Status) => {
const statusUri = foreignStatus.uri;
const statusUrl = foreignStatus.url;
return this.getInstanceInfo(account)
.then(instance => {
let version: 'v1' | 'v2' = 'v1';
if (instance.major >= 3) version = 'v2';
return this.mastodonService.search(account, statusUri, version, true)
.then((results: Results) => {
if(results && results.statuses.length > 0) return results;
return this.mastodonService.search(account, statusUrl, version, true);
});
})
.then((results: Results) => {
return results.statuses[0];
});
return this.mastodonService.getStatus(foreignStatus.id);
});
}