업로드 정리 및 S3에서 업로드 삭제

:bookmark: 이 참고 자료는 고아(Orphaned) 및 삭제된 업로드가 Discourse 사이트에서 자동으로 정리되는 방식을 설명합니다. 이 가이드는 셀프 호스팅 및 호스팅된 Discourse 사이트 모두에 적용됩니다.

:person_raising_hand: 필요한 사용자 권한: 관리자

Discourse 사이트에 업로드되었지만 더 이상 참조되지 않는 파일과 이미지에 대해 어떤 일이 발생하는지, 또는 사이트에서 업로드를 삭제하는 방법에 대해 궁금해하신 적 있으신가요? 올바른 곳으로 오셨습니다!

더 이상 참조되지 않는 Discourse에 업로드된 파일과 이미지를 삭제해야 할 수 있습니다. 사용자 인터페이스에서 이를 수행하는 내장된 방법은 없지만, Discourse에는 고아 및 삭제된 업로드를 제거하도록 예약된 자동 Sidekiq 작업인 clean up uploads가 있습니다.

고아 및 삭제된 업로드

:information_source: 고아 업로드는 Discourse 사이트에 업로드되었지만 더 이상 참조되지 않는 파일입니다. 업로드는 오직 다음 조건에 해당할 때만 고아로 간주됩니다:

  • 게시물의 최신 버전에서
  • 초안에서
  • 대기 중인 게시물에서
  • 사이트 설정(예: 로고, 파비콘)에서
  • 사용자 정의 이모지에서
  • 테마에서
  • 사용자 아바타/배경/카드 이미지에서
  • 카테고리 로고/배경 이미지에서
  • 배지 이미지에서
  • 그룹 플레어 이미지에서

:information_source: 업로드가 포함된 주제/게시물이 삭제되면 업로드는 "삭제됨"으로 간주됩니다.

업로드 정리

업로드를 Discourse에서 완전히 제거하려면 다음 중 하나를 수행해야 합니다:

  • 업로드에 대한 모든 참조를 제거하여 업로드가 고아가 되도록 강제합니다. 이는 업로드가 포함된 게시물에서 업로드 링크를 편집하여 제거하거나, 업로드가 참조될 수 있는 다른 모든 위치에서 참조를 제거함으로써 수행할 수 있습니다.
  • 업로드를 포함하는 모든 주제/게시물을 삭제하여 업로드가 "삭제됨"으로 간주되도록 합니다. 게시물을 삭제하기 전에 고아로 만들려면 게시물에서 이미지를 제거해야 한다는 점에 유의하세요.

이후 clean up uploads 작업이 실행되면(유예 기간 후) 모든 고아 미참조 업로드 및 삭제된 업로드가 저장소에서 제거됩니다.

사이트 설정

Discourse가 업로드를 자동으로 정리하는 방식을 수정하기 위해 다음 사이트 설정이 example.discourse.com/admin/site_settings/category/files에서 사용할 수 있습니다.

  • clean up uploads: 기본값 true
  • clean orphan uploads grace period hours: 기본값 48
  • purge deleted uploads grace period days: 기본값 30

clean up uploads 설정은 고아 미참조 업로드의 자동 삭제를 활성화하거나 비활성화하는 데 사용할 수 있습니다. clean orphan uploads grace period hours 설정은 감지된 고아 업로드가 정리되기까지 얼마나 오래 유지되는지 제어합니다. purge deleted uploads grace period days 설정은 톰스톤(삭제됨) 업로드가 영구적으로 제거되기 전에 얼마나 오래 유지되는지 제어하며, 이는 별도의 purge deleted uploads 예약 작업에 의해 처리됩니다.

clean up uploads 작업에 대한 추가 세부 사항은 GitHub의 clean_up_uploads.rb 파일에서 확인할 수 있습니다.

S3 업로드 정리

:warning: 다음 섹션은 셀프 호스팅된 Discourse 사이트에만 적용됩니다.

:information_source: 현재 Enterprise Plan으로 호스팅되고 계신 경우, S3 저장소에서 업로드를 삭제하는 것에 대해 질문이 있으면 team@discourse.org로 문의해 주세요.

고아 및 삭제된 업로드 정리는 로컬 및 S3 저장소 모두에서 유사하게 작동합니다. 로컬 저장소와 S3 저장소 간의 유일한 차이점은 S3 업로드의 정리가 S3를 통해 tombstone 정책으로 자동으로 처리된다는 것입니다. S3에서 이것이 어떻게 처리되는지에 대한 추가 세부 사항은 스토리지 수명 관리를 참조하세요.

기본적으로 clean up uploads 작업에는 S3 업로드가 포함됩니다. 그러나 이 기능을 비활성화하려면 s3 configure tombstone policy 사이트 설정의 체크를 해제할 수 있습니다.

4개의 좋아요

Is this accurate? I think you need to remove the image from the post before deleting the post to orphan it.

Also, should this last one be purge deleted uploads grace period days?

1개의 좋아요

Enabling “clean up uploads” sounds scary with the warning message. When converting an existing forum to discourse this setting will be disabled. Not all import scripts will properly register all the uploads in posts, so if you enable it, you might lose a lot of attachments.

With the following query you can check if uploads are properly referenced by the posts:

select p.post_id, u.id as upload_id
from (select id post_id, (regexp_matches(cooked, 'data-download-href=[^\s]+/default/([a-z0-9]+)', 'g'))[1] upload_sha from posts where raw like '%upload://%' order by created_at) as p 
join uploads u on u.sha1 = p.upload_sha
where not exists(select * from upload_references r where r.upload_id = u.id)

That should not return any rows if everything is correct. If you use this query in the Data Explorer plugin it will also neatly link to the posts which have unreferenced attachments.

If the above query does return results you can fix the missing upload references with the following query:

insert into upload_references(upload_id, target_type, target_id, created_at, updated_at)
select u.id, 'Post', p.post_id, u.created_at, u.updated_at 
from (select id post_id, (regexp_matches(cooked, 'data-download-href=[^\s]+/default/([a-z0-9]+)', 'g'))[1] upload_sha from posts where raw like '%upload://%' order by created_at) as p 
join uploads u on u.sha1 = p.upload_sha
on conflict do nothing;

You will need direct database access in order to make the corrective change.