use /users endpoint for explore exclusively (restore original behavior)

This commit is contained in:
Hazelnoot 2025-05-12 22:43:19 -04:00
parent bb8609d0f0
commit b7b30bde5d
4 changed files with 14 additions and 30 deletions

16
locales/index.d.ts vendored
View file

@ -13057,14 +13057,14 @@ export interface Locale extends ILocale {
* Users popular on {name}
*/
"popularUsersLocal": ParameterizedString<"name">;
/**
* Translation timeout
*/
"translationTimeoutLabel": string;
/**
* Timeout in milliseconds for translation API requests.
*/
"translationTimeoutCaption": string;
/**
* Translation timeout
*/
"translationTimeoutLabel": string;
/**
* Timeout in milliseconds for translation API requests.
*/
"translationTimeoutCaption": string;
}
declare const locales: {
[lang: string]: Locale;

View file

@ -50,7 +50,6 @@ export const paramDef = {
default: null,
description: 'The local host is represented with `null`.',
},
trending: { type: 'boolean', default: false },
},
required: [],
} as const;
@ -67,12 +66,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const query = this.usersRepository.createQueryBuilder('user')
.andWhere('user.isExplorable = TRUE')
.andWhere('user.isSuspended = FALSE');
if (ps.trending) {
query.andWhere('user.isExplorable = TRUE');
}
switch (ps.state) {
case 'alive': query.andWhere('user.updatedAt > :date', { date: new Date(Date.now() - 1000 * 60 * 60 * 24 * 5) }); break;
}
@ -104,18 +100,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
query.limit(ps.limit);
query.offset(ps.offset);
let users = await query.getMany();
const allUsers = await query.getMany();
// This is not ideal, for a couple of reasons:
// 1. It may return less than "limit" results.
// 2. A span of more than "limit" consecutive non-trendable users may cause the pagination to stop early.
// Unfortunately, there's no better solution unless we refactor role policies to be persisted to the DB.
if (ps.trending) {
const usersWithRoles = await Promise.all(users.map(async u => [u, await this.roleService.getUserPolicies(u)] as const));
users = usersWithRoles
.filter(([,p]) => p.canTrend)
.map(([u]) => u);
}
const usersWithRoles = await Promise.all(allUsers.map(async u => [u, await this.roleService.getUserPolicies(u)] as const));
const users = usersWithRoles
.filter(([,p]) => p.canTrend)
.map(([u]) => u);
return await this.userEntityService.packMany(users, me, { schema: 'UserDetailed' });
});

View file

@ -97,7 +97,6 @@ const tagUsers = computed(() => ({
tag: props.tag,
origin: 'combined',
sort: '+follower',
trending: true,
},
} as const));
@ -106,40 +105,33 @@ const popularUsers = { endpoint: 'users', limit: 10, noPaging: true, params: {
state: 'alive',
origin: 'local',
sort: '+follower',
trending: true,
} } as const;
const recentlyUpdatedUsers = { endpoint: 'users', limit: 10, noPaging: true, params: {
origin: 'local',
sort: '+updatedAt',
trending: true,
} } as const;
const recentlyRegisteredUsers = { endpoint: 'users', limit: 10, noPaging: true, params: {
origin: 'local',
state: 'alive',
sort: '+createdAt',
trending: true,
} } as const;
const popularUsersF = { endpoint: 'users', limit: 10, noPaging: true, params: {
state: 'alive',
origin: 'remote',
sort: '+follower',
trending: true,
} } as const;
const popularUsersLocalF = { endpoint: 'users', limit: 10, noPaging: true, params: {
state: 'alive',
origin: 'remote',
sort: '+localFollower',
trending: true,
} } as const;
const recentlyUpdatedUsersF = { endpoint: 'users', limit: 10, noPaging: true, params: {
origin: 'combined',
sort: '+updatedAt',
trending: true,
} } as const;
const recentlyRegisteredUsersF = { endpoint: 'users', limit: 10, noPaging: true, params: {
origin: 'combined',
sort: '+createdAt',
trending: true,
} } as const;
misskeyApi('hashtags/list', {

View file

@ -31541,8 +31541,6 @@ export type operations = {
* @default null
*/
hostname?: string | null;
/** @default false */
trending?: boolean;
};
};
};