π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: fetch post faster
Nevo David774d29d79847
diff --git a/apps/backend/src/api/routes/posts.controller.ts b/apps/backend/src/api/routes/posts.controller.tsindex c51852ee6..ce03df002 100644--- a/apps/backend/src/api/routes/posts.controller.ts+++ b/apps/backend/src/api/routes/posts.controller.ts@@ -22,7 +22,10 @@ import { Response } from 'express';import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request';import { ShortLinkService } from '@gitroom/nestjs-libraries/short-linking/short.link.service';import { CreateTagDto } from '@gitroom/nestjs-libraries/dtos/posts/create.tag.dto';-import { AuthorizationActions, Sections } from '@gitroom/backend/services/auth/permissions/permission.exception.class';+import {+ AuthorizationActions,+ Sections,+} from '@gitroom/backend/services/auth/permissions/permission.exception.class';@ApiTags('Posts')@Controller('/posts')@@ -111,6 +114,11 @@ export class PostsController {return this._postsService.getOldPosts(org.id, date);}+ @Get('/group/:group')+ getPostsByGroup(@GetOrgFromRequest() org: Organization, @Param('group') group: string) {+ return this._postsService.getPostsByGroup(org.id, group);+ }+@Get('/:id')getPost(@GetOrgFromRequest() org: Organization, @Param('id') id: string) {return this._postsService.getPost(org.id, id);diff --git a/apps/frontend/src/components/launches/calendar.tsx b/apps/frontend/src/components/launches/calendar.tsxindex 997218f89..f0dbb4f65 100644--- a/apps/frontend/src/components/launches/calendar.tsx+++ b/apps/frontend/src/components/launches/calendar.tsx@@ -454,7 +454,7 @@ export const CalendarColumn: FC<{publishDate: loadPost.actualDate || loadPost.publishDate,};- const data = await (await fetch(`/posts/${post.id}`)).json();+ const data = await (await fetch(`/posts/group/${post.group}`)).json();const date = !isDuplicate? null: (await (await fetch('/posts/find-slot')).json()).date;diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.tsindex cb2a647aa..56efa445b 100644--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts@@ -49,7 +49,7 @@ export class PostsRepository {integration: {select: {providerIdentifier: true,- }+ },},publishDate: true,},@@ -235,6 +235,24 @@ export class PostsRepository {});}+ getPostsByGroup(orgId: string, group: string) {+ return this._post.model.post.findMany({+ where: {+ group,+ ...(orgId ? { organizationId: orgId } : {}),+ deletedAt: null,+ },+ include: {+ integration: true,+ tags: {+ select: {+ tag: true,+ },+ },+ },+ });+ }+getPost(id: string,includeIntegration = false,diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.tsindex d8dfd75dd..98cc144b4 100644--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.service.ts@@ -252,6 +252,47 @@ export class PostsService {}}+ async getPostsByGroup(orgId: string, group: string) {+ const convertToJPEG = false;+ const loadAll = await this._postRepository.getPostsByGroup(orgId, group);+ const posts = this.arrangePostsByGroup(loadAll, undefined);++ return {+ group: posts?.[0]?.group,+ posts: await Promise.all(+ (posts || []).map(async (post) => ({+ ...post,+ image: await this.updateMedia(+ post.id,+ JSON.parse(post.image || '[]'),+ convertToJPEG+ ),+ }))+ ),+ integrationPicture: posts[0]?.integration?.picture,+ integration: posts[0].integrationId,+ settings: JSON.parse(posts[0].settings || '{}'),+ };+ }++ arrangePostsByGroup(all: any, parent?: string): PostWithConditionals[] {+ const findAll = all+ .filter((p: any) =>+ !parent ? !p.parentPostId : p.parentPostId === parent+ )+ .map(({ integration, ...all }: any) => ({+ ...all,+ ...(!parent ? { integration } : {}),+ }));++ return [+ ...findAll,+ ...(findAll.length+ ? findAll.flatMap((p: any) => this.arrangePostsByGroup(all, p.id))+ : []),+ ];+ }+async getPost(orgId: string, id: string, convertToJPEG = false) {const posts = await this.getPostsRecursively(id, true, orgId, true);const list = {