7
7
from typing import IO , Any
8
8
9
9
import zstandard
10
- from django .conf import settings
11
10
from django .core .cache import cache
12
11
from django .core .exceptions import ObjectDoesNotExist
13
12
from django .db import models
@@ -169,7 +168,7 @@ def getfile(self) -> IO[bytes]:
169
168
170
169
@classmethod
171
170
def putfile (cls , project_id : int , attachment : CachedAttachment ) -> PutfileResult :
172
- from sentry .models .files import File , FileBlob
171
+ from sentry .models .files import FileBlob
173
172
174
173
content_type = normalize_content_type (attachment .content_type , attachment .name )
175
174
data = attachment .data
@@ -179,34 +178,19 @@ def putfile(cls, project_id: int, attachment: CachedAttachment) -> PutfileResult
179
178
180
179
blob = BytesIO (data )
181
180
182
- # NOTE: we still keep the old code around for a while before complete removing it
183
- store_blobs = True
181
+ size , checksum = get_size_and_checksum (blob )
184
182
185
- if store_blobs :
186
- size , checksum = get_size_and_checksum (blob )
187
-
188
- if can_store_inline (data ) and in_random_rollout ("eventattachments.store-small-inline" ):
189
- blob_path = ":" + data .decode ()
190
- else :
191
- blob_path = "eventattachments/v1/" + FileBlob .generate_unique_path ()
192
-
193
- storage = get_storage ()
194
- compressed_blob = BytesIO (zstandard .compress (data ))
195
- storage .save (blob_path , compressed_blob )
196
-
197
- return PutfileResult (
198
- content_type = content_type , size = size , sha1 = checksum , blob_path = blob_path
199
- )
183
+ if can_store_inline (data ) and in_random_rollout ("eventattachments.store-small-inline" ):
184
+ blob_path = ":" + data .decode ()
185
+ else :
186
+ blob_path = "eventattachments/v1/" + FileBlob .generate_unique_path ()
200
187
201
- file = File .objects .create (
202
- name = attachment .name ,
203
- type = attachment .type ,
204
- headers = {"Content-Type" : content_type },
205
- )
206
- file .putfile (blob , blob_size = settings .SENTRY_ATTACHMENT_BLOB_SIZE )
188
+ storage = get_storage ()
189
+ compressed_blob = BytesIO (zstandard .compress (data ))
190
+ storage .save (blob_path , compressed_blob )
207
191
208
192
return PutfileResult (
209
- content_type = content_type , size = file . size , sha1 = file . checksum , file_id = file . id
193
+ content_type = content_type , size = size , sha1 = checksum , blob_path = blob_path
210
194
)
211
195
212
196
0 commit comments