Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
0964c207
Commit
0964c207
authored
Jan 04, 2019
by
kaniini
Browse files
rich media: use cachex to avoid flooding remote servers
parent
4258dd86
Pipeline
#6006
failed with stages
in 3 minutes and 15 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/application.ex
View file @
0964c207
...
...
@@ -63,6 +63,17 @@ def start(_type, _args) do
],
id:
:cachex_object
),
worker
(
Cachex
,
[
:rich_media_cache
,
[
default_ttl:
:timer
.
minutes
(
120
),
limit:
5000
]
],
id:
:cachex_rich_media
),
worker
(
Cachex
,
[
...
...
lib/pleroma/web/rich_media/parser.ex
View file @
0964c207
...
...
@@ -2,9 +2,13 @@ defmodule Pleroma.Web.RichMedia.Parser do
@parsers
[
Pleroma
.
Web
.
RichMedia
.
Parsers
.
OGP
]
def
parse
(
url
)
do
{
:ok
,
%
Tesla
.
Env
{
body:
html
}}
=
Pleroma
.
HTTP
.
get
(
url
)
Cachex
.
fetch!
(
:rich_media_cache
,
url
,
fn
_
->
{
:ok
,
%
Tesla
.
Env
{
body:
html
}}
=
Pleroma
.
HTTP
.
get
(
url
)
html
|>
maybe_parse
()
|>
get_parsed_data
()
result
=
html
|>
maybe_parse
()
|>
get_parsed_data
()
{
:commit
,
result
}
end
)
end
defp
maybe_parse
(
html
)
do
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment