Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Mastodon
Commits
3caec1ec
Commit
3caec1ec
authored
7 years ago
by
abcang
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Save media outside transaction (#5959)
parent
2950de86
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/lib/activitypub/activity/create.rb
+19
-3
19 additions, 3 deletions
app/lib/activitypub/activity/create.rb
app/lib/ostatus/activity/creation.rb
+17
-4
17 additions, 4 deletions
app/lib/ostatus/activity/creation.rb
with
36 additions
and
7 deletions
app/lib/activitypub/activity/create.rb
+
19
−
3
View file @
3caec1ec
...
@@ -20,11 +20,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
...
@@ -20,11 +20,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
private
private
def
process_status
def
process_status
media_attachments
=
process_attachments
ApplicationRecord
.
transaction
do
ApplicationRecord
.
transaction
do
@status
=
Status
.
create!
(
status_params
)
@status
=
Status
.
create!
(
status_params
)
process_tags
(
@status
)
process_tags
(
@status
)
process_
attachme
nts
(
@status
)
attach
_
me
dia
(
@status
,
media_attachments
)
end
end
resolve_thread
(
@status
)
resolve_thread
(
@status
)
...
@@ -105,22 +107,36 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
...
@@ -105,22 +107,36 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
emoji
.
save
emoji
.
save
end
end
def
process_attachments
(
status
)
def
process_attachments
return
if
@object
[
'attachment'
].
nil?
return
if
@object
[
'attachment'
].
nil?
media_attachments
=
[]
as_array
(
@object
[
'attachment'
]).
each
do
|
attachment
|
as_array
(
@object
[
'attachment'
]).
each
do
|
attachment
|
next
if
unsupported_media_type?
(
attachment
[
'mediaType'
])
||
attachment
[
'url'
].
blank?
next
if
unsupported_media_type?
(
attachment
[
'mediaType'
])
||
attachment
[
'url'
].
blank?
href
=
Addressable
::
URI
.
parse
(
attachment
[
'url'
]).
normalize
.
to_s
href
=
Addressable
::
URI
.
parse
(
attachment
[
'url'
]).
normalize
.
to_s
media_attachment
=
MediaAttachment
.
create
(
status:
status
,
account:
status
.
account
,
remote_url:
href
,
description:
attachment
[
'name'
].
presence
)
media_attachment
=
MediaAttachment
.
create
(
account:
@account
,
remote_url:
href
,
description:
attachment
[
'name'
].
presence
)
media_attachments
<<
media_attachment
next
if
skip_download?
next
if
skip_download?
media_attachment
.
file_remote_url
=
href
media_attachment
.
file_remote_url
=
href
media_attachment
.
save
media_attachment
.
save
end
end
media_attachments
rescue
Addressable
::
URI
::
InvalidURIError
=>
e
rescue
Addressable
::
URI
::
InvalidURIError
=>
e
Rails
.
logger
.
debug
e
Rails
.
logger
.
debug
e
media_attachments
end
def
attach_media
(
status
,
media_attachments
)
return
if
media_attachments
.
blank?
media
=
MediaAttachment
.
where
(
status_id:
nil
,
id:
media_attachments
.
take
(
4
).
map
(
&
:id
))
media
.
update
(
status_id:
status
.
id
)
end
end
def
resolve_thread
(
status
)
def
resolve_thread
(
status
)
...
...
This diff is collapsed.
Click to expand it.
app/lib/ostatus/activity/creation.rb
+
17
−
4
View file @
3caec1ec
...
@@ -26,6 +26,8 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
...
@@ -26,6 +26,8 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
cached_reblog
=
reblog
cached_reblog
=
reblog
status
=
nil
status
=
nil
media_attachments
=
save_media
ApplicationRecord
.
transaction
do
ApplicationRecord
.
transaction
do
status
=
Status
.
create!
(
status
=
Status
.
create!
(
uri:
id
,
uri:
id
,
...
@@ -44,7 +46,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
...
@@ -44,7 +46,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
save_mentions
(
status
)
save_mentions
(
status
)
save_hashtags
(
status
)
save_hashtags
(
status
)
save
_media
(
status
)
attach
_media
(
status
,
media_attachments
)
save_emojis
(
status
)
save_emojis
(
status
)
end
end
...
@@ -126,18 +128,20 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
...
@@ -126,18 +128,20 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
ProcessHashtagsService
.
new
.
call
(
parent
,
tags
)
ProcessHashtagsService
.
new
.
call
(
parent
,
tags
)
end
end
def
save_media
(
parent
)
def
save_media
do_not_download
=
DomainBlock
.
find_by
(
domain:
parent
.
account
.
domain
)
&
.
reject_media?
do_not_download
=
DomainBlock
.
find_by
(
domain:
@account
.
domain
)
&
.
reject_media?
media_attachments
=
[]
@xml
.
xpath
(
'./xmlns:link[@rel="enclosure"]'
,
xmlns:
OStatus
::
TagManager
::
XMLNS
).
each
do
|
link
|
@xml
.
xpath
(
'./xmlns:link[@rel="enclosure"]'
,
xmlns:
OStatus
::
TagManager
::
XMLNS
).
each
do
|
link
|
next
unless
link
[
'href'
]
next
unless
link
[
'href'
]
media
=
MediaAttachment
.
where
(
status:
parent
,
remote_url:
link
[
'href'
]).
first_or_initialize
(
account:
parent
.
account
,
status:
parent
,
remote_url:
link
[
'href'
])
media
=
MediaAttachment
.
where
(
status:
nil
,
remote_url:
link
[
'href'
]).
first_or_initialize
(
account:
@
account
,
status:
nil
,
remote_url:
link
[
'href'
])
parsed_url
=
Addressable
::
URI
.
parse
(
link
[
'href'
]).
normalize
parsed_url
=
Addressable
::
URI
.
parse
(
link
[
'href'
]).
normalize
next
if
!
%w(http https)
.
include?
(
parsed_url
.
scheme
)
||
parsed_url
.
host
.
empty?
next
if
!
%w(http https)
.
include?
(
parsed_url
.
scheme
)
||
parsed_url
.
host
.
empty?
media
.
save
media
.
save
media_attachments
<<
media
next
if
do_not_download
next
if
do_not_download
...
@@ -148,6 +152,15 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
...
@@ -148,6 +152,15 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
next
next
end
end
end
end
media_attachments
end
def
attach_media
(
parent
,
media_attachments
)
return
if
media_attachments
.
blank?
media
=
MediaAttachment
.
where
(
status_id:
nil
,
id:
media_attachments
.
take
(
4
).
map
(
&
:id
))
media
.
update
(
status_id:
parent
.
id
)
end
end
def
save_emojis
(
parent
)
def
save_emojis
(
parent
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment