Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alex Gleason
pleroma
Commits
034986e1
Commit
034986e1
authored
5 years ago
by
kaniini
Browse files
Options
Downloads
Patches
Plain Diff
MRF: add mediaproxy warming policy
parent
c6668c2e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex
+56
-0
56 additions, 0 deletions
...pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex
with
56 additions
and
0 deletions
lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex
0 → 100644
+
56
−
0
View file @
034986e1
# Pleroma: A lightweight social networking server
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Web
.
ActivityPub
.
MRF
.
MediaProxyWarmingPolicy
do
@moduledoc
"Preloads any attachments in the MediaProxy cache by prefetching them"
@behaviour
Pleroma
.
Web
.
ActivityPub
.
MRF
alias
Pleroma
.
HTTP
alias
Pleroma
.
Web
.
MediaProxy
require
Logger
@hackney_options
[
pool:
:media
,
recv_timeout:
10_000
]
def
perform
(
:prefetch
,
url
)
do
Logger
.
info
(
"Prefetching
#{
inspect
(
url
)
}
"
)
url
|>
MediaProxy
.
url
()
|>
HTTP
.
get
([],
adapter:
@hackney_options
)
end
def
perform
(
:preload
,
%{
"object"
=>
%{
"attachment"
=>
attachments
}}
=
_message
)
do
Enum
.
each
(
attachments
,
fn
%{
"url"
=>
url
}
when
is_list
(
url
)
->
url
|>
Enum
.
each
(
fn
%{
"href"
=>
href
}
->
PleromaJobQueue
.
enqueue
(
:background
,
__MODULE__
,
[
:prefetch
,
href
])
x
->
Logger
.
debug
(
"Unhandled attachment URL object
#{
inspect
(
x
)
}
"
)
end
)
x
->
Logger
.
debug
(
"Unhandled attachment
#{
inspect
(
x
)
}
"
)
end
)
end
@impl
true
def
filter
(
%{
"type"
=>
"Create"
,
"object"
=>
%{
"attachment"
=>
attachments
}
=
_object
}
=
message
)
when
is_list
(
attachments
)
and
length
(
attachments
)
>
0
do
PleromaJobQueue
.
enqueue
(
:background
,
__MODULE__
,
[
:preload
,
message
])
{
:ok
,
message
}
end
@impl
true
def
filter
(
message
),
do
:
{
:ok
,
message
}
end
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