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
935e65e2
Commit
935e65e2
authored
Jan 30, 2019
by
lain
Browse files
Use race-condition free following method.
parent
aa98a100
Pipeline
#6797
failed with stages
in 5 minutes and 32 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
935e65e2
...
...
@@ -343,18 +343,17 @@ def follow(%User{} = follower, %User{info: info} = followed) do
Websub
.
subscribe
(
follower
,
followed
)
end
following
=
[
ap_followers
|
follower
.
following
]
|>
Enum
.
uniq
()
q
=
from
(
u
in
User
,
where:
u
.
id
==
^
follower
.
id
,
update:
[
push:
[
following:
^
ap_followers
]]
)
follower
=
follower
|>
follow_changeset
(%{
following:
following
})
|>
update_and_set_cache
{
1
,
[
follower
]}
=
Repo
.
update_all
(
q
,
[],
returning:
true
)
{
:ok
,
_
}
=
update_follower_count
(
followed
)
follower
set_cache
(
follower
)
end
end
...
...
@@ -362,17 +361,18 @@ def unfollow(%User{} = follower, %User{} = followed) do
ap_followers
=
followed
.
follower_address
if
following?
(
follower
,
followed
)
and
follower
.
ap_id
!=
followed
.
ap_id
do
following
=
follower
.
following
|>
List
.
delete
(
ap_followers
)
q
=
from
(
u
in
User
,
where:
u
.
id
==
^
follower
.
id
,
update:
[
pull:
[
following:
^
ap_followers
]]
)
{
:ok
,
follower
}
=
follower
|>
follow_changeset
(%{
following:
following
})
|>
update_and_set_cache
{
1
,
[
follower
]}
=
Repo
.
update_all
(
q
,
[],
returning:
true
)
{
:ok
,
followed
}
=
update_follower_count
(
followed
)
set_cache
(
follower
)
{
:ok
,
follower
,
Utils
.
fetch_latest_follow
(
follower
,
followed
)}
else
{
:error
,
"Not subscribed!"
}
...
...
@@ -423,12 +423,16 @@ def get_by_guessed_nickname(ap_id) do
get_by_nickname
(
nickname
)
end
def
set_cache
(
user
)
do
Cachex
.
put
(
:user_cache
,
"ap_id:
#{
user
.
ap_id
}
"
,
user
)
Cachex
.
put
(
:user_cache
,
"nickname:
#{
user
.
nickname
}
"
,
user
)
Cachex
.
put
(
:user_cache
,
"user_info:
#{
user
.
id
}
"
,
user_info
(
user
))
{
:ok
,
user
}
end
def
update_and_set_cache
(
changeset
)
do
with
{
:ok
,
user
}
<-
Repo
.
update
(
changeset
)
do
Cachex
.
put
(
:user_cache
,
"ap_id:
#{
user
.
ap_id
}
"
,
user
)
Cachex
.
put
(
:user_cache
,
"nickname:
#{
user
.
nickname
}
"
,
user
)
Cachex
.
put
(
:user_cache
,
"user_info:
#{
user
.
id
}
"
,
user_info
(
user
))
{
:ok
,
user
}
set_cache
(
user
)
else
e
->
e
end
...
...
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