Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hakaba Hitoyo
pleroma
Commits
d53e36bf
Commit
d53e36bf
authored
Feb 11, 2019
by
lain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'object-creation' into 'develop'"
This reverts merge request !802
parent
06c4935c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
53 deletions
+19
-53
lib/pleroma/object.ex
lib/pleroma/object.ex
+1
-21
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/activity_pub/utils.ex
+8
-2
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api.ex
+10
-2
test/object_test.exs
test/object_test.exs
+0
-28
No files found.
lib/pleroma/object.ex
View file @
d53e36bf
...
...
@@ -20,29 +20,9 @@ defmodule Pleroma.Object do
timestamps
()
end
def
insert_or_get
(
cng
)
do
{
_
,
data
}
=
fetch_field
(
cng
,
:data
)
id
=
data
[
"id"
]
||
data
[
:id
]
key
=
"object:
#{
id
}
"
fetcher
=
fn
_
->
with
nil
<-
get_by_ap_id
(
id
),
{
:ok
,
object
}
<-
Repo
.
insert
(
cng
)
do
{
:commit
,
object
}
else
%
Object
{}
=
object
->
{
:commit
,
object
}
e
->
{
:ignore
,
e
}
end
end
with
{
state
,
object
}
when
state
in
[
:commit
,
:ok
]
<-
Cachex
.
fetch
(
:object_cache
,
key
,
fetcher
)
do
{
:ok
,
object
}
end
end
def
create
(
data
)
do
Object
.
change
(%
Object
{},
%{
data:
data
})
|>
insert_or_ge
t
()
|>
Repo
.
inser
t
()
end
def
change
(
struct
,
params
\\
%{})
do
...
...
lib/pleroma/web/activity_pub/utils.ex
View file @
d53e36bf
...
...
@@ -142,8 +142,14 @@ def create_context(context) do
context
=
context
||
generate_id
(
"contexts"
)
changeset
=
Object
.
context_mapping
(
context
)
with
{
:ok
,
object
}
<-
Object
.
insert_or_get
(
changeset
)
do
object
case
Repo
.
insert
(
changeset
)
do
{
:ok
,
object
}
->
object
# This should be solved by an upsert, but it seems ecto
# has problems accessing the constraint inside the jsonb.
{
:error
,
_
}
->
Object
.
get_cached_by_ap_id
(
context
)
end
end
...
...
lib/pleroma/web/twitter_api/twitter_api.ex
View file @
d53e36bf
...
...
@@ -310,8 +310,16 @@ def context_to_conversation_id(context) do
else
_e
->
changeset
=
Object
.
context_mapping
(
context
)
{
:ok
,
object
}
=
Object
.
insert_or_get
(
changeset
)
object
.
id
case
Repo
.
insert
(
changeset
)
do
{
:ok
,
%{
id:
id
}}
->
id
# This should be solved by an upsert, but it seems ecto
# has problems accessing the constraint inside the jsonb.
{
:error
,
_
}
->
Object
.
get_cached_by_ap_id
(
context
)
.
id
end
end
end
...
...
test/object_test.exs
View file @
d53e36bf
...
...
@@ -57,32 +57,4 @@ test "ensures cache is cleared for the object" do
assert
cached_object
.
data
[
"type"
]
==
"Tombstone"
end
end
describe
"insert_or_get"
do
test
"inserting the same object twice (by id) just returns the original object"
do
data
=
%{
data:
%{
"id"
=>
Ecto
.
UUID
.
generate
()}}
cng
=
Object
.
change
(%
Object
{},
data
)
{
:ok
,
object
}
=
Object
.
insert_or_get
(
cng
)
{
:ok
,
second_object
}
=
Object
.
insert_or_get
(
cng
)
Cachex
.
clear
(
:object_cache
)
{
:ok
,
third_object
}
=
Object
.
insert_or_get
(
cng
)
assert
object
==
second_object
assert
object
==
third_object
end
end
describe
"create"
do
test
"inserts an object for a given data set"
do
data
=
%{
"id"
=>
Ecto
.
UUID
.
generate
()}
{
:ok
,
object
}
=
Object
.
create
(
data
)
assert
object
.
data
[
"id"
]
==
data
[
"id"
]
# Works when doing it twice.
{
:ok
,
object
}
=
Object
.
create
(
data
)
assert
object
.
data
[
"id"
]
==
data
[
"id"
]
end
end
end
Write
Preview
Markdown
is supported
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