Browse Source

Add activities indices

pull/43/head
Toromino 1 month ago
parent
commit
5b223ef628

+ 4
- 0
migrations/2019-04-22-180257_introduce_indices/down.sql View File

@@ -0,0 +1,4 @@
1
+DROP INDEX IF EXISTS activities_ap_actor;
2
+DROP INDEX IF EXISTS activities_ap_cc;
3
+DROP INDEX IF EXISTS activities_ap_public;
4
+DROP INDEX IF EXISTS activities_ap_to;

+ 4
- 0
migrations/2019-04-22-180257_introduce_indices/up.sql View File

@@ -0,0 +1,4 @@
1
+CREATE INDEX activities_ap_actor ON activities ((data->'actor'));
2
+CREATE INDEX activities_ap_cc ON activities USING GIN ((data->'cc'));
3
+CREATE INDEX activities_ap_public ON activities ((data->'to')) WHERE (data->'to')::jsonb ? 'https://www.w3.org/ns/activitystreams#Public';
4
+CREATE INDEX activities_ap_to ON activities USING GIN ((data->'to'));

+ 8
- 8
src/timeline.rs View File

@@ -30,8 +30,8 @@ pub fn get_home_timeline(
30 30
         "SELECT id \
31 31
          FROM activities \
32 32
          WHERE \
33
-         (data->>'type' = 'Create' OR \
34
-         data->>'type' = 'Announce') AND \
33
+         (data @> '{{\"type\": \"Create\"}}' OR \
34
+         data @> '{{\"type\": \"Announce\"}}') AND \
35 35
          (actor_uri = ANY (ARRAY['{followees}']::varchar(255)[]) OR \
36 36
          actor_uri = '{actor_uri}') \
37 37
          {id} \
@@ -74,8 +74,8 @@ pub fn get_public_timeline(
74 74
     match sql_query(format!(
75 75
         "SELECT id \
76 76
          FROM activities \
77
-         WHERE data->>'type' = 'Create' AND \
78
-         (data->>'to')::jsonb ? 'https://www.w3.org/ns/activitystreams#Public' \
77
+         WHERE data @> '{{\"type\": \"Create\"}}' AND \
78
+         data -> 'to' ? 'https://www.w3.org/ns/activitystreams#Public' \
79 79
          {local} \
80 80
          {id} \
81 81
          LIMIT {limit};",
@@ -107,11 +107,11 @@ pub fn get_user_timeline(
107 107
         "SELECT id \
108 108
          FROM activities \
109 109
          WHERE \
110
-         (data->>'type' = 'Create' OR \
111
-         data->>'type' = 'Announce') AND \
110
+         (data @> '{{\"type\": \"Create\"}}' OR \
111
+         data @> '{{\"type\": \"Announce\"}}') AND \
112 112
          actor_uri = '{actor_uri}' AND \
113
-         ((data->>'to')::jsonb ? 'https://www.w3.org/ns/activitystreams#Public' OR \
114
-         (data->>'cc')::jsonb ? 'https://www.w3.org/ns/activitystreams#Public') \
113
+         (data -> 'to' ? 'https://www.w3.org/ns/activitystreams#Public' OR \
114
+         data -> 'cc' ? 'https://www.w3.org/ns/activitystreams#Public') \
115 115
          {id} \
116 116
          LIMIT {limit};",
117 117
         actor_uri = runtime_escape(&actor.actor_uri),

Loading…
Cancel
Save