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
68a14056
Commit
68a14056
authored
Nov 01, 2018
by
kaniini
Browse files
Merge branch 'refactor/object-cache-deletion' into 'develop'
refactor object cache deletion See merge request
pleroma/pleroma!408
parents
33587f5c
f55fc68f
Pipeline
#4216
passed with stages
in 6 minutes
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/object.ex
View file @
68a14056
defmodule
Pleroma
.
Object
do
use
Ecto
.
Schema
alias
Pleroma
.
{
Repo
,
Object
}
alias
Pleroma
.
{
Repo
,
Object
,
Activity
}
import
Ecto
.
{
Query
,
Changeset
}
schema
"objects"
do
...
...
@@ -52,4 +52,12 @@ def get_cached_by_ap_id(ap_id) do
def
context_mapping
(
context
)
do
Object
.
change
(%
Object
{},
%{
data:
%{
"id"
=>
context
}})
end
def
delete
(%
Object
{
data:
%{
"id"
=>
id
}}
=
object
)
do
with
Repo
.
delete
(
object
),
Repo
.
delete_all
(
Activity
.
all_non_create_by_object_ap_id_q
(
id
)),
{
:ok
,
true
}
<-
Cachex
.
del
(
:user_cache
,
"object:
#{
id
}
"
)
do
:ok
end
end
end
lib/pleroma/web/activity_pub/activity_pub.ex
View file @
68a14056
...
...
@@ -273,8 +273,7 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru
"to"
=>
[
user
.
follower_address
,
"https://www.w3.org/ns/activitystreams#Public"
]
}
with
Repo
.
delete
(
object
),
Repo
.
delete_all
(
Activity
.
all_non_create_by_object_ap_id_q
(
id
)),
with
Object
.
delete
(
object
),
{
:ok
,
activity
}
<-
insert
(
data
,
local
),
:ok
<-
maybe_federate
(
activity
),
{
:ok
,
_actor
}
<-
User
.
decrease_note_count
(
user
)
do
...
...
lib/pleroma/web/common_api/common_api.ex
View file @
68a14056
...
...
@@ -9,8 +9,7 @@ def delete(activity_id, user) do
with
%
Activity
{
data:
%{
"object"
=>
%{
"id"
=>
object_id
}}}
<-
Repo
.
get
(
Activity
,
activity_id
),
%
Object
{}
=
object
<-
Object
.
normalize
(
object_id
),
true
<-
user
.
info
[
"is_moderator"
]
||
user
.
ap_id
==
object
.
data
[
"actor"
],
{
:ok
,
delete
}
<-
ActivityPub
.
delete
(
object
),
{
:ok
,
true
}
<-
Cachex
.
del
(
:user_cache
,
"object:
#{
object_id
}
"
)
do
{
:ok
,
delete
}
<-
ActivityPub
.
delete
(
object
)
do
{
:ok
,
delete
}
end
end
...
...
test/object_test.exs
View file @
68a14056
...
...
@@ -19,4 +19,34 @@ test "it ensures uniqueness of the id" do
{
:error
,
_result
}
=
Repo
.
insert
(
cs
)
end
end
describe
"deletion function"
do
test
"deletes an object"
do
object
=
insert
(
:note
)
found_object
=
Object
.
get_by_ap_id
(
object
.
data
[
"id"
])
assert
object
==
found_object
Object
.
delete
(
found_object
)
found_object
=
Object
.
get_by_ap_id
(
object
.
data
[
"id"
])
refute
object
==
found_object
end
test
"ensures cache is cleared for the object"
do
object
=
insert
(
:note
)
cached_object
=
Object
.
get_cached_by_ap_id
(
object
.
data
[
"id"
])
assert
object
==
cached_object
Object
.
delete
(
cached_object
)
{
:ok
,
nil
}
=
Cachex
.
get
(
:user_cache
,
"object:
#{
object
.
data
[
"id"
]
}
"
)
cached_object
=
Object
.
get_cached_by_ap_id
(
object
.
data
[
"id"
])
refute
object
==
cached_object
end
end
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