Skip to content

Commit

Permalink
fix(article): rss 로딩 오래걸림 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
gracefulBrown committed May 29, 2024
1 parent f20f07f commit d3c91ff
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void sendSlackMessage(Article article) {

// Context block
String name = article.getMember().getNickname() + "(" + article.getMember().getUsername() + ")";
String date = article.getCreatedAt().toLocalDate().toString();
String date = article.getPublishedAt().toLocalDate().toString();
ContextBlock contextBlock = ContextBlock.builder()
.elements(Collections.singletonList(
MarkdownTextObject.builder()
Expand Down
18 changes: 14 additions & 4 deletions backend/src/main/java/wooteco/prolog/article/domain/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import wooteco.prolog.common.exception.BadRequestException;
import wooteco.prolog.member.domain.Member;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
Expand All @@ -21,6 +22,7 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.time.LocalDateTime;
import java.time.ZoneId;

import static java.lang.Boolean.TRUE;

Expand Down Expand Up @@ -50,6 +52,9 @@ public class Article {
@Embedded
private ImageUrl imageUrl;

@Column
private LocalDateTime publishedAt;

@Embedded
private ArticleBookmarks articleBookmarks;

Expand All @@ -62,28 +67,33 @@ public class Article {
@Embedded
private ViewCount views;

public Article(Member member, Title title, Description description, Url url, ImageUrl imageUrl) {
this(member, title, description, url, imageUrl, null);
}

public Article(Member member, Title title, Url url, ImageUrl imageUrl) {
this(member, title, new Description(), url, imageUrl);
this(member, title, new Description(), url, imageUrl, null);
}

public Article(Member member, Title title, Description description, Url url, ImageUrl imageUrl) {
public Article(Member member, Title title, Description description, Url url, ImageUrl imageUrl, LocalDateTime publishedAt) {
this.member = member;
this.title = title;
this.description = description;
this.url = url;
this.imageUrl = imageUrl;
this.publishedAt = publishedAt;
this.articleBookmarks = new ArticleBookmarks();
this.articleLikes = new ArticleLikes();
this.views = new ViewCount();
}

public static Article of(Member member, SyndFeed syndFeed, SyndEntry entry) {
Title title = new Title(entry.getTitle());
Description description = new Description(entry.getDescription().getValue());
ImageUrl imageUrl = ImageUrl.of(entry.getDescription().getValue(), syndFeed.getImage().getUrl());
Description description = new Description(entry.getDescription().getValue());
LocalDateTime publishedAt = entry.getPublishedDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();

return new Article(member, title, description, new Url(entry.getLink()), imageUrl);
return new Article(member, title, description, new Url(entry.getLink()), imageUrl, publishedAt);
}

public void validateOwner(final Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public Description(String description) {
if (description == null || description.isEmpty() || description.trim().isEmpty()) {
description = "내용없음";
}
if (description.length() > 100) {
description = description.substring(0, 100);
}

this.description = StringEscapeUtils.unescapeHtml4(Jsoup.clean(description, Safelist.none()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ImageUrl(String url) {
if (Objects.isNull(url) || url.isEmpty() || url.trim().isEmpty() || url.length() > MAX_LENGTH) {
url = "https://avatars.githubusercontent.com/u/45747236?s=200&v=4";
}
this.url = url.trim();
this.url = url;
}

public static ImageUrl of(String description, String defaultUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public Title(String title) {
if (title.length() > MAX_LENGTH) {
title = title.substring(0, MAX_LENGTH);
}
title = StringEscapeUtils.unescapeHtml4(Jsoup.clean(title, Safelist.none()));

this.title = title;
this.title = title.trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ ALTER TABLE member

ALTER TABLE article
ADD COLUMN description VARCHAR(256) AFTER title;

ALTER TABLE article
ADD COLUMN published_at datetime(6) AFTER image_url;
50 changes: 25 additions & 25 deletions frontend/src/components/ProfilePageSideBar/ProfilePageSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,31 @@ const ProfilePageSideBar = ({ menu }: ProfilePageSideBarProps) => {
</Button>
)}
</NicknameWrapper>
{/*<RssLinkLabel>RSS Link</RssLinkLabel>*/}
{/*<RssFeedWrapper>*/}
{/* {isRssFeedEditing ? (*/}
{/* <RssFeedInput*/}
{/* autoFocus*/}
{/* value={rssFeedUrl}*/}
{/* onChange={({ target }) => setRssFeedUrl(target.value)}*/}
{/* />*/}
{/* ) : (*/}
{/* <RssFeedUrl>{rssFeedUrl}</RssFeedUrl>*/}
{/* )}*/}
{/* {isOwner && (*/}
{/* <Button*/}
{/* size={BUTTON_SIZE.X_SMALL}*/}
{/* type="button"*/}
{/* css={EditButtonStyle}*/}
{/* alt={isRssFeedEditing ? '수정 완료 버튼' : '수정 버튼'}*/}
{/* onClick={() => {*/}
{/* isRssFeedEditing ? editProfile() : setIsRssFeedEditing(true);*/}
{/* }}*/}
{/* >*/}
{/* {isRssFeedEditing ? '완료' : '수정'}*/}
{/* </Button>*/}
{/* )}*/}
{/*</RssFeedWrapper>*/}
<RssLinkLabel>RSS Link</RssLinkLabel>
<RssFeedWrapper>
{isRssFeedEditing ? (
<RssFeedInput
autoFocus
value={rssFeedUrl}
onChange={({ target }) => setRssFeedUrl(target.value)}
/>
) : (
<RssFeedUrl>{rssFeedUrl}</RssFeedUrl>
)}
{isOwner && (
<Button
size={BUTTON_SIZE.X_SMALL}
type="button"
css={EditButtonStyle}
alt={isRssFeedEditing ? '수정 완료 버튼' : '수정 버튼'}
onClick={() => {
isRssFeedEditing ? editProfile() : setIsRssFeedEditing(true);
}}
>
{isRssFeedEditing ? '완료' : '수정'}
</Button>
)}
</RssFeedWrapper>
</Profile>
{isLoading ? <></> : <BadgeList badgeList={badgeList} />}
<MenuList>
Expand Down

0 comments on commit d3c91ff

Please sign in to comment.