client, server: merge nearby pool posts into regular post serialization

Can still be cleaned up some more.
Need to compare speed of the get_around query vs nearby pool posts.
This commit is contained in:
Eva
2025-04-03 01:39:09 +02:00
parent 7708b4e5a3
commit 3875ec173f
8 changed files with 67 additions and 81 deletions

View File

@ -17,11 +17,6 @@ class PostMainController extends BasePostController {
constructor(ctx, editMode) {
super(ctx);
let poolPostsNearby = Promise.resolve({results: []});
if (api.hasPrivilege("pools:list") && api.hasPrivilege("pools:view")) {
poolPostsNearby = PostList.getNearbyPoolPosts(ctx.parameters.id);
}
let parameters = ctx.parameters;
Promise.all([
Post.get(ctx.parameters.id),
@ -29,10 +24,9 @@ class PostMainController extends BasePostController {
ctx.parameters.id,
parameters ? parameters.query : null
),
poolPostsNearby
]).then(
(responses) => {
const [post, aroundResponse, poolPostsNearby] = responses;
const [post, aroundResponse] = responses;
let aroundPool = null;
// remove junk from query, but save it into history so that it can
@ -51,9 +45,9 @@ class PostMainController extends BasePostController {
const found = item.match(/^pool:([0-9]+)/i);
if (found) {
const activePool = parseInt(found[1]);
poolPostsNearby.forEach((nearbyPosts) => {
if (nearbyPosts.pool.id == activePool) {
aroundPool = nearbyPosts
post.pools.map((pool) => {
if (pool.id == activePool) {
aroundPool = pool;
}
});
}
@ -63,7 +57,6 @@ class PostMainController extends BasePostController {
this._post = post;
this._view = new PostMainView({
post: post,
poolPostsNearby: poolPostsNearby,
editMode: editMode,
prevPostId: aroundPool
? (aroundPool.previousPost ? aroundPool.previousPost.id : null)