]> git.mxchange.org Git - friendica.git/blob - static/dbview.config.php
Some performance tweeks
[friendica.git] / static / dbview.config.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * Main view structure configuration file.
21  *
22  * Here are described all the view Friendica needs to work.
23  *
24  * Syntax (braces indicate optionale values):
25  * "<view name>" => [
26  *      "fields" => [
27  *              "<field name>" => ["table", "field"],
28  *              "<field name>" => "SQL expression",
29  *              ...
30  *      ],
31  *      "query" => "FROM `table` INNER JOIN `other-table` ..."
32  *      ],
33  * ],
34  *
35  * If you need to make any change, make sure to increment the DB_UPDATE_VERSION constant value in dbstructure.config.php.
36  *
37  */
38
39 return [
40         "category-view" => [
41                 "fields" => [
42                         "uri-id" => ["post-category", "uri-id"],
43                         "uid" => ["post-category", "uid"],
44                         "uri" => ["item-uri", "uri"],
45                         "guid" => ["item-uri", "guid"],
46                         "type" => ["post-category", "type"],
47                         "tid" => ["post-category", "tid"],
48                         "name" => ["tag", "name"],
49                         "url" => ["tag", "url"],
50                 ],
51                 "query" => "FROM `post-category`
52                         INNER JOIN `item-uri` ON `item-uri`.id = `post-category`.`uri-id`
53                         LEFT JOIN `tag` ON `post-category`.`tid` = `tag`.`id`"
54         ],
55         "tag-view" => [
56                 "fields" => [
57                         "uri-id" => ["post-tag", "uri-id"],
58                         "uri" => ["item-uri", "uri"],
59                         "guid" => ["item-uri", "guid"],
60                         "type" => ["post-tag", "type"],
61                         "tid" => ["post-tag", "tid"],
62                         "cid" => ["post-tag", "cid"],
63                         "name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END",
64                         "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END",
65                 ],
66                 "query" => "FROM `post-tag`
67                         INNER JOIN `item-uri` ON `item-uri`.id = `post-tag`.`uri-id`
68                         LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
69                         LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`"
70         ],
71         "network-item-view" => [
72                 "fields" => [
73                         "uri-id" => ["item", "parent-uri-id"],
74                         "uri" => ["item", "parent-uri"],
75                         "parent" => ["item", "parent"],
76                         "received" => ["item", "received"],
77                         "commented" => ["item", "commented"],
78                         "created" => ["item", "created"],
79                         "uid" => ["item", "uid"],
80                         "starred" => ["item", "starred"],
81                         "mention" => ["item", "mention"],
82                         "network" => ["item", "network"],
83                         "unseen" => ["item", "unseen"],
84                         "gravity" => ["item", "gravity"],
85                         "contact-id" => ["item", "contact-id"],
86                 ],
87                 "query" => "FROM `item`
88                         INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
89                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
90                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
91                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
92                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
93                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
94                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
95                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
96                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)"
97         ],
98         "network-thread-view" => [
99                 "fields" => [
100                         "uri-id" => ["item", "uri-id"],
101                         "uri" => ["item", "uri"],
102                         "parent-uri-id" => ["item", "parent-uri-id"],
103                         "parent" => ["thread", "iid"],
104                         "received" => ["thread", "received"],
105                         "commented" => ["thread", "commented"],
106                         "created" => ["thread", "created"],
107                         "uid" => ["thread", "uid"],
108                         "starred" => ["thread", "starred"],
109                         "mention" => ["thread", "mention"],
110                         "network" => ["thread", "network"],
111                         "contact-id" => ["thread", "contact-id"],
112                 ],
113                 "query" => "FROM `thread`
114                         STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
115                         STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
116                         LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
117                         LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
118                         LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
119                         WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
120                         AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
121                         AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
122                         AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)"
123         ],
124         "owner-view" => [
125                 "fields" => [
126                         "id" => ["contact", "id"],
127                         "uid" => ["contact", "uid"],
128                         "created" => ["contact", "created"],
129                         "updated" => ["contact", "updated"],
130                         "self" => ["contact", "self"],
131                         "remote_self" => ["contact", "remote_self"],
132                         "rel" => ["contact", "rel"],
133                         "duplex" => ["contact", "duplex"],
134                         "network" => ["contact", "network"],
135                         "protocol" => ["contact", "protocol"],
136                         "name" => ["contact", "name"],
137                         "nick" => ["contact", "nick"],
138                         "location" => ["contact", "location"],
139                         "about" => ["contact", "about"],
140                         "keywords" => ["contact", "keywords"],
141                         "gender" => ["contact", "gender"],
142                         "xmpp" => ["contact", "xmpp"],
143                         "attag" => ["contact", "attag"],
144                         "avatar" => ["contact", "avatar"],
145                         "photo" => ["contact", "photo"],
146                         "thumb" => ["contact", "thumb"],
147                         "micro" => ["contact", "micro"],
148                         "site-pubkey" => ["contact", "site-pubkey"],
149                         "issued-id" => ["contact", "issued-id"],
150                         "dfrn-id" => ["contact", "dfrn-id"],
151                         "url" => ["contact", "url"],
152                         "nurl" => ["contact", "nurl"],
153                         "addr" => ["contact", "addr"],
154                         "alias" => ["contact", "alias"],
155                         "pubkey" => ["contact", "pubkey"],
156                         "prvkey" => ["contact", "prvkey"],
157                         "batch" => ["contact", "batch"],
158                         "request" => ["contact", "request"],
159                         "notify" => ["contact", "notify"],
160                         "poll" => ["contact", "poll"],
161                         "confirm" => ["contact", "confirm"],
162                         "poco" => ["contact", "poco"],
163                         "aes_allow" => ["contact", "aes_allow"],
164                         "ret-aes" => ["contact", "ret-aes"],
165                         "usehub" => ["contact", "usehub"],
166                         "subhub" => ["contact", "subhub"],
167                         "hub-verify" => ["contact", "hub-verify"],
168                         "last-update" => ["contact", "last-update"],
169                         "success_update" => ["contact", "success_update"],
170                         "failure_update" => ["contact", "failure_update"],
171                         "name-date" => ["contact", "name-date"],
172                         "uri-date" => ["contact", "uri-date"],
173                         "avatar-date" => ["contact", "avatar-date"],
174                         "picdate" => ["contact", "avatar-date"], /// @todo Replaces all uses of "picdate" with "avatar-date"
175                         "term-date" => ["contact", "term-date"],
176                         "last-item" => ["contact", "last-item"],
177                         "priority" => ["contact", "priority"],
178                         "blocked" => ["contact", "blocked"], /// @todo Check if "blocked" from contact or from the users table
179                         "block_reason" => ["contact", "block_reason"],
180                         "readonly" => ["contact", "readonly"],
181                         "writable" => ["contact", "writable"],
182                         "forum" => ["contact", "forum"],
183                         "prv" => ["contact", "prv"],
184                         "contact-type" => ["contact", "contact-type"],
185                         "hidden" => ["contact", "hidden"],
186                         "archive" => ["contact", "archive"],
187                         "pending" => ["contact", "pending"],
188                         "deleted" => ["contact", "deleted"],
189                         "rating" => ["contact", "rating"],
190                         "unsearchable" => ["contact", "unsearchable"],
191                         "sensitive" => ["contact", "sensitive"],
192                         "baseurl" => ["contact", "baseurl"],
193                         "reason" => ["contact", "reason"],
194                         "closeness" => ["contact", "closeness"],
195                         "info" => ["contact", "info"],
196                         "profile-id" => ["contact", "profile-id"],
197                         "bdyear" => ["contact", "bdyear"],
198                         "bd" => ["contact", "bd"],
199                         "notify_new_posts" => ["contact", "notify_new_posts"],
200                         "fetch_further_information" => ["contact", "fetch_further_information"],
201                         "ffi_keyword_denylist" => ["contact", "ffi_keyword_denylist"],
202                         "parent-uid" => ["user", "parent-uid"],
203                         "guid" => ["user", "guid"],
204                         "nickname" => ["user", "nickname"], /// @todo Replaces all uses of "nickname" with "nick"
205                         "email" => ["user", "email"],
206                         "openid" => ["user", "openid"],
207                         "timezone" => ["user", "timezone"],
208                         "language" => ["user", "language"],
209                         "register_date" => ["user", "register_date"],
210                         "login_date" => ["user", "login_date"],
211                         "default-location" => ["user", "default-location"],
212                         "allow_location" => ["user", "allow_location"],
213                         "theme" => ["user", "theme"],
214                         "upubkey" => ["user", "pubkey"],
215                         "uprvkey" => ["user", "prvkey"],
216                         "sprvkey" => ["user", "sprvkey"],
217                         "spubkey" => ["user", "spubkey"],
218                         "verified" => ["user", "verified"],
219                         "blockwall" => ["user", "blockwall"],
220                         "hidewall" => ["user", "hidewall"],
221                         "blocktags" => ["user", "blocktags"],
222                         "unkmail" => ["user", "unkmail"],
223                         "cntunkmail" => ["user", "cntunkmail"],
224                         "notify-flags" => ["user", "notify-flags"],
225                         "page-flags" => ["user", "page-flags"],
226                         "account-type" => ["user", "account-type"],
227                         "prvnets" => ["user", "prvnets"],
228                         "maxreq" => ["user", "maxreq"],
229                         "expire" => ["user", "expire"],
230                         "account_removed" => ["user", "account_removed"],
231                         "account_expired" => ["user", "account_expired"],
232                         "account_expires_on" => ["user", "account_expires_on"],
233                         "expire_notification_sent" => ["user", "expire_notification_sent"],
234                         "def_gid" => ["user", "def_gid"],
235                         "allow_cid" => ["user", "allow_cid"],
236                         "allow_gid" => ["user", "allow_gid"],
237                         "deny_cid" => ["user", "deny_cid"],
238                         "deny_gid" => ["user", "deny_gid"],
239                         "openidserver" => ["user", "openidserver"],
240                         "publish" => ["profile", "publish"],
241                         "net-publish" => ["profile", "net-publish"],
242                         "hide-friends" => ["profile", "hide-friends"],
243                         "prv_keywords" => ["profile", "prv_keywords"],
244                         "pub_keywords" => ["profile", "pub_keywords"],
245                         "address" => ["profile", "address"],
246                         "locality" => ["profile", "locality"],
247                         "region" => ["profile", "region"],
248                         "postal-code" => ["profile", "postal-code"],
249                         "country-name" => ["profile", "country-name"],
250                         "homepage" => ["profile", "homepage"],
251                         "dob" => ["profile", "dob"],
252                 ],
253                 "query" => "FROM `user`
254                         INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
255                         INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid`"
256         ],
257         "pending-view" => [
258                 "fields" => [
259                         "id" => ["register", "id"],
260                         "hash" => ["register", "hash"],
261                         "created" => ["register", "created"],
262                         "uid" => ["register", "uid"],
263                         "password" => ["register", "password"],
264                         "language" => ["register", "language"],
265                         "note" => ["register", "note"],
266                         "self" => ["contact", "self"],
267                         "name" => ["contact", "name"],
268                         "url" => ["contact", "url"],
269                         "micro" => ["contact", "micro"],
270                         "email" => ["user", "email"],
271                         "nick" => ["contact", "nick"],
272                 ],
273                 "query" => "FROM `register`
274                         INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
275                         INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
276         ],
277         "tag-search-view" => [
278                 "fields" => [
279                         "uri-id" => ["post-tag", "uri-id"],
280                         "iid" => ["item", "id"],
281                         "uri" => ["item", "uri"],
282                         "guid" => ["item", "guid"],
283                         "uid" => ["item", "uid"],
284                         "private" => ["item", "private"],
285                         "wall" => ["item", "wall"],
286                         "origin" => ["item", "origin"],
287                         "gravity" => ["item", "gravity"],
288                         "received" => ["item", "received"],                     
289                         "name" => ["tag", "name"],
290                 ],
291                 "query" => "FROM `post-tag`
292                         INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
293                         INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id`
294                         WHERE `post-tag`.`type` = 1"
295         ],
296         "workerqueue-view" => [
297                 "fields" => [
298                         "pid" => ["process", "pid"],
299                         "priority" => ["workerqueue", "priority"],
300                 ],
301                 "query" => "FROM `process`
302                         INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
303                         WHERE NOT `workerqueue`.`done`"
304         ],
305 ];
306