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
9cf38d67
Commit
9cf38d67
authored
Jun 20, 2017
by
lain
Browse files
Use more efficient queries.
parent
14a9dd46
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/activity.ex
View file @
9cf38d67
...
...
@@ -17,11 +17,12 @@ def get_by_ap_id(ap_id) do
def
all_by_object_ap_id
(
ap_id
)
do
Repo
.
all
(
from
activity
in
Activity
,
where:
fragment
(
"
? @>
?"
,
activity
.
data
,
^
%{
object:
%{
id:
ap_id
}}
))
where:
fragment
(
"
(?)->'object'->>'id' =
?"
,
activity
.
data
,
^
to_string
(
ap_id
)
))
end
def
get_create_activity_by_object_ap_id
(
ap_id
)
do
Repo
.
one
(
from
activity
in
Activity
,
where:
fragment
(
"? @> ?"
,
activity
.
data
,
^
%{
type:
"Create"
,
object:
%{
id:
ap_id
}}))
where:
fragment
(
"(?)->'object'->>'id' = ?"
,
activity
.
data
,
^
to_string
(
ap_id
))
and
fragment
(
"(?)->>'type' = 'Create'"
,
activity
.
data
))
end
end
priv/repo/migrations/20170620133028_add_object_activity_index.exs
0 → 100644
View file @
9cf38d67
defmodule
Pleroma
.
Repo
.
Migrations
.
AddObjectActivityIndex
do
use
Ecto
.
Migration
def
change
do
create
index
(
:objects
,
[
"(data->'object'->>'id')"
,
"(data->>'type')"
],
name:
:activities_create_objects_index
)
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