Skip to content

Commit c6da4d8

Browse files
authored
Merge pull request #40 from 01-binary/add-pmap
feat: Optimize image blur generation with p-map concurrency and remov…
2 parents dfda96a + 7dbc89a commit c6da4d8

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
},
1313
"dependencies": {
1414
"dayjs": "^1.11.8",
15-
"is-url-superb": "^6.1.0",
1615
"jotai": "^2.8.0",
1716
"lodash": "^4.17.21",
1817
"next": "^14.2.4",
1918
"notion-to-jsx": "^1.2.8",
2019
"notion-to-utils": "^1.1.1",
21-
"p-map": "^7.0.2",
20+
"p-map": "^7.0.3",
2221
"plaiceholder": "^3.0.0",
2322
"prismjs": "^1.30.0",
2423
"react": "^18.2.0",

pages/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useHydrateAtoms } from 'jotai/utils';
22
import { GetStaticProps } from 'next';
3+
import pMap from 'p-map';
34

45
import { categoriesAtom } from '@/atoms/categories';
56
import { postsAtom } from '@/atoms/posts';
@@ -52,11 +53,15 @@ export const getStaticProps: GetStaticProps<Props> = async () => {
5253

5354
const profileUrl = await fetchNotionProfileUrl();
5455
const notionPostsResponse = await fetchNotionPostsMeta(process.env.NOTION_POST_DATABASE_ID);
55-
const posts = await Promise.all(
56-
getPostsMeta(notionPostsResponse).map(async (post) => ({
57-
...post,
58-
blurImage: await getBlurImage(post.cover),
59-
})),
56+
57+
const allPostsMeta = getPostsMeta(notionPostsResponse);
58+
const posts = await pMap(
59+
allPostsMeta,
60+
async (post: PostMeta) => {
61+
const blurImage = await getBlurImage(post.cover);
62+
return { ...post, blurImage };
63+
},
64+
{ concurrency: 10 },
6065
);
6166
const categories = getCategories(notionPostsResponse);
6267

pnpm-lock.yaml

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/getBlurImage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const getBlurImage = async (imgSrc: string) => {
66
const { base64 } = await getPlaiceholder(buffer, { size: 10 });
77
return base64;
88
} catch (e) {
9-
console.log(`[getBlurImage] 오류 발생: ${imgSrc}`, e);
9+
console.log(`[getBlurImage] 오류 발생: ${imgSrc}`);
1010
return '';
1111
}
1212
};

0 commit comments

Comments
 (0)