<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jung Yunho on Medium]]></title>
        <description><![CDATA[Stories by Jung Yunho on Medium]]></description>
        <link>https://medium.com/@yunhobb?source=rss-1e06c65325d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rAMC-nfkimKrtmyc</url>
            <title>Stories by Jung Yunho on Medium</title>
            <link>https://medium.com/@yunhobb?source=rss-1e06c65325d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:42:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yunhobb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Open api 도입기]]></title>
            <link>https://medium.com/@yunhobb/open-api-%EB%8F%84%EC%9E%85%EA%B8%B0-020cc988fa12?source=rss-1e06c65325d------2</link>
            <guid isPermaLink="false">https://medium.com/p/020cc988fa12</guid>
            <dc:creator><![CDATA[Jung Yunho]]></dc:creator>
            <pubDate>Fri, 24 Nov 2023 07:20:00 GMT</pubDate>
            <atom:updated>2023-11-24T07:20:00.608Z</atom:updated>
            <content:encoded><![CDATA[<h3>어쩌다?</h3><p>주제를 선정하던 중 서울시에서 진행하는 문화행사 정보를 모아둔 api가 있는 것을 팀원분이 찾아오셨다. 데이터를 미리 확보해 활용을 할 수 있는 장점이있어 해당 프로젝트 주제를 선정하게 되었다.</p><h3>그래서?</h3><p><a href="https://data.seoul.go.kr/together/guide/useGuide.do">오픈PAPI 소개</a></p><p>서울시 열린데이터 광장의 Open api는 이용방법이 잘 설명되어 있다. <br>이용방법에 나와있는 것 처럼 진행을 하면 되었는데 한가지 걸리는 문장이 있었다.</p><blockquote>오픈 API를 통해서 한번에 최대 1,000건을 요청할 수 있습니다.</blockquote><p>요청을 통해서 최대 1000건 밖에 요청을 못받는 것이다!!<br>혹시나 하는 마음에 요청을 보내봤으나 당연하게도 데이터는 반환 받는 총 데이터는 1000건이 넘었다.</p><h3>코드</h3><h4>데이터 받아오기</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UsRnEpvaSYaPGSsmI99JGw.png" /></figure><p>Open api에서 <strong><em>list_total_count</em></strong> 를 반환 받기 위하여 하나의 데이터만 요청을 보내 값을 가져왔다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHJWfE7enQ_eG0NS9zVzfA.png" /></figure><p>위의 요청을 통해 받아온 <strong><em>list_total_count</em></strong>를 활용하여 1000개씩 데이터를 반환하도록 코드를 구성을 하였고</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZxTmddLgngHULbNKM6FhA.png" /></figure><p>데이터를 받아오게 구성을 하였다.</p><h4>반복은?</h4><p>@Scheduled을 사용하여 위의 요청을 자동으로 받아오게 하였다.</p><pre>@Scheduled(fixedDelay = 1000 * 60 * 60 * 24, initialDelay = 3000) </pre><h3>Ver — 2</h3><h4>save -&gt; saveAll</h4><p>기존에는 데이터를 받아오면 colume 하나마다 save메서드를 사용하여 추가를 하였다.</p><p>save와 saveAll 메서드는 성능차이가 크게 존재한다는 것을 알게 되었고 변경을 하였다.</p><p>(인터넷에 자료가 많고 프로젝트 회고록이니 관련 내용은 담지 않겠다. <br>성능차이를 검색해 보는것을 추천한다)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*Ij2u7u2g8CjHJZSgPmfHdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*yHGCEvhWo1ALHaihSVM1MA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qPQbXTQZMDaoVIvuZOSHXg.png" /></figure><p>위와 같이 구성을 해 개선을 하였다.</p><p><strong>287ms -&gt; 260ms 로 미비하게 개선이 되었지만 <br>데이터의 규모가 커질수록 성능은 크게 개선이 될 것이다.</strong></p><h4><strong>추가되는</strong> 데이터</h4><p><a href="https://data.seoul.go.kr/dataList/OA-15486/S/1/datasetView.do">data.seoul.go.kr</a> 에서는 오전 9시에 업데이트 되는 데이터가 있으면 추가가 된다고 하였다. <br>새로 업데이트 되는 값을 DB에 추가하기 위하여 업데이트된 내용만 받아 올 수 있는지 조사를 하였으나 Open api측에서는 해당 기능이 없다.<br>따라서 Service로직에서 해결을 해야겠다 생각을 하였다.</p><p><strong>설계 방향이다</strong></p><ul><li>반환되는 값 중 고유한 값이 title(행사 제목)이다.</li><li>findByTitle메서드를 활용해 반환되는 개수가 0 이면 값을 save한다.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N3HTmWXXPb_BRJHxCR5pjg.png" /></figure><p>위와 같은 코드를 추가해 @Scheduled 어노테이션을 활용해 24시간 마다 돌리도록 하였다.</p><h4>saveAll을 @PostConstruct 로</h4><p>기존에 초기 데이터를 저장하는 로직은 서버가 실행시 한번만 추가를 하면 된다.</p><p>따라서 Bean주입과 의존성 주입이 완료 된 후 실행되는 @PostConstruct를 활용해 saveAll을 하도록 변경하였다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=020cc988fa12" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>