2017-07-08 03:27:09 +08:00
|
|
|
Model = require('../../src/flux/models/model').default
|
2016-10-27 07:01:23 +08:00
|
|
|
Category = require('../../src/flux/models/category').default
|
2016-09-22 00:40:06 +08:00
|
|
|
Attributes = require('../../src/flux/attributes').default
|
2015-06-26 22:42:41 +08:00
|
|
|
|
|
|
|
class TestModel extends Model
|
|
|
|
@attributes =
|
|
|
|
'id': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'id'
|
|
|
|
|
2015-08-29 02:12:53 +08:00
|
|
|
'clientId': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'clientId'
|
|
|
|
jsonKey: 'client_id'
|
|
|
|
|
2017-06-25 11:03:35 +08:00
|
|
|
'serverId': Attributes.String
|
2015-08-29 02:12:53 +08:00
|
|
|
queryable: true
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
|
|
|
|
2015-06-26 22:42:41 +08:00
|
|
|
TestModel.configureBasic = ->
|
|
|
|
TestModel.attributes =
|
|
|
|
'id': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'id'
|
2015-08-29 02:12:53 +08:00
|
|
|
'clientId': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'clientId'
|
|
|
|
jsonKey: 'client_id'
|
2017-06-25 11:03:35 +08:00
|
|
|
'serverId': Attributes.String
|
2015-08-29 02:12:53 +08:00
|
|
|
queryable: true
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
2015-06-26 22:42:41 +08:00
|
|
|
|
|
|
|
TestModel.configureWithAllAttributes = ->
|
|
|
|
TestModel.attributes =
|
|
|
|
'datetime': Attributes.DateTime
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'datetime'
|
|
|
|
'string': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'string'
|
|
|
|
jsonKey: 'string-json-key'
|
|
|
|
'boolean': Attributes.Boolean
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'boolean'
|
|
|
|
'number': Attributes.Number
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'number'
|
|
|
|
'other': Attributes.String
|
|
|
|
modelKey: 'other'
|
|
|
|
|
|
|
|
TestModel.configureWithCollectionAttribute = ->
|
|
|
|
TestModel.attributes =
|
|
|
|
'id': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'id'
|
2015-08-29 02:12:53 +08:00
|
|
|
'clientId': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'clientId'
|
|
|
|
jsonKey: 'client_id'
|
2017-06-25 11:03:35 +08:00
|
|
|
'serverId': Attributes.String
|
2015-08-29 02:12:53 +08:00
|
|
|
queryable: true
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
perf(db): Use subselect to improve thread list query perf (53%!)
Summary:
- Use a sub-select query with much better performance to display the thread list
- Perform analyze on tables after launch
The new query is:
```
SELECT `Thread`.`data` FROM `Thread` WHERE `Thread`.`id` IN (SELECT `id` FROM `ThreadCategory` AS `M26` WHERE `M26`.`value` IN ('9m9ks71k06n5rmx82kgues09p','9s9k25q6j1krjgpkovbcjm7d','13b7ufruoymvih07ki0uahlto','dtmhlzz6phr47zp512knhjgf8','16dvjb84bszfh15kgfrjj37i3','aclwmgncdqjfibp51bvgbeik','17qad7jhbp6tozog3klm5zagt','4x4bkbawiq825u4eu3aus8tll','7axr9f5f1lzpwm2rw2ghkirhq','dsnn660af0pmou2gg3nstga8a','361qr5rva1ieby2r0ec3sn0bm','10fyvba7pjyjgeyr5i65i1zri') AND `M26`.`in_all_mail` = 1 ORDER BY `M26`.`last_message_received_timestamp` DESC LIMIT 200 OFFSET 0) ORDER BY `Thread`.`last_message_received_timestamp` DESC;
`
0|0|0|SEARCH TABLE Thread USING INDEX Thread_id (id=?)
0|0|0|EXECUTE LIST SUBQUERY 1
1|0|0|SCAN TABLE Thread-Category AS M26 USING COVERING INDEX ThreadFancyIndex
1|0|0|EXECUTE LIST SUBQUERY 2
0|0|0|USE TEMP B-TREE FOR (only on 200 result items)
```
Which is twice as performant as:
```
SELECT `Thread`.`data` FROM `Thread` INNER JOIN `ThreadCategory` AS `M26` ON `M26`.`id` = `Thread`.`id` WHERE `M26`.`value` IN ('9m9ks71k06n5rmx82kgues09p','9s9k25q6j1krjgpkovbcjm7d','13b7ufruoymvih07ki0uahlto','dtmhlzz6phr47zp512knhjgf8','16dvjb84bszfh15kgfrjj37i3','aclwmgncdqjfibp51bvgbeik','17qad7jhbp6tozog3klm5zagt','4x4bkbawiq825u4eu3aus8tll','7axr9f5f1lzpwm2rw2ghkirhq','361qr5rva1ieby2r0ec3sn0bm','10fyvba7pjyjgeyr5i65i1zri') AND `M26`.`in_all_mail` = 1 ORDER BY `M26`.`last_message_received_timestamp` DESC LIMIT 200 OFFSET 0;
0|0|1|SCAN TABLE Thread-Category AS M26 USING COVERING INDEX ThreadFancyIndex
0|0|0|EXECUTE LIST SUBQUERY 1
0|1|0|SEARCH TABLE Thread USING INDEX Thread_id (id=?)
```
Test Plan: Broken!
Reviewers: evan, juan
Reviewed By: juan
Differential Revision: https://phab.nylas.com/D2869
2016-04-12 04:29:05 +08:00
|
|
|
'other': Attributes.String
|
|
|
|
queryable: true,
|
|
|
|
modelKey: 'other'
|
2016-01-26 03:11:57 +08:00
|
|
|
'categories': Attributes.Collection
|
perf(db): Use subselect to improve thread list query perf (53%!)
Summary:
- Use a sub-select query with much better performance to display the thread list
- Perform analyze on tables after launch
The new query is:
```
SELECT `Thread`.`data` FROM `Thread` WHERE `Thread`.`id` IN (SELECT `id` FROM `ThreadCategory` AS `M26` WHERE `M26`.`value` IN ('9m9ks71k06n5rmx82kgues09p','9s9k25q6j1krjgpkovbcjm7d','13b7ufruoymvih07ki0uahlto','dtmhlzz6phr47zp512knhjgf8','16dvjb84bszfh15kgfrjj37i3','aclwmgncdqjfibp51bvgbeik','17qad7jhbp6tozog3klm5zagt','4x4bkbawiq825u4eu3aus8tll','7axr9f5f1lzpwm2rw2ghkirhq','dsnn660af0pmou2gg3nstga8a','361qr5rva1ieby2r0ec3sn0bm','10fyvba7pjyjgeyr5i65i1zri') AND `M26`.`in_all_mail` = 1 ORDER BY `M26`.`last_message_received_timestamp` DESC LIMIT 200 OFFSET 0) ORDER BY `Thread`.`last_message_received_timestamp` DESC;
`
0|0|0|SEARCH TABLE Thread USING INDEX Thread_id (id=?)
0|0|0|EXECUTE LIST SUBQUERY 1
1|0|0|SCAN TABLE Thread-Category AS M26 USING COVERING INDEX ThreadFancyIndex
1|0|0|EXECUTE LIST SUBQUERY 2
0|0|0|USE TEMP B-TREE FOR (only on 200 result items)
```
Which is twice as performant as:
```
SELECT `Thread`.`data` FROM `Thread` INNER JOIN `ThreadCategory` AS `M26` ON `M26`.`id` = `Thread`.`id` WHERE `M26`.`value` IN ('9m9ks71k06n5rmx82kgues09p','9s9k25q6j1krjgpkovbcjm7d','13b7ufruoymvih07ki0uahlto','dtmhlzz6phr47zp512knhjgf8','16dvjb84bszfh15kgfrjj37i3','aclwmgncdqjfibp51bvgbeik','17qad7jhbp6tozog3klm5zagt','4x4bkbawiq825u4eu3aus8tll','7axr9f5f1lzpwm2rw2ghkirhq','361qr5rva1ieby2r0ec3sn0bm','10fyvba7pjyjgeyr5i65i1zri') AND `M26`.`in_all_mail` = 1 ORDER BY `M26`.`last_message_received_timestamp` DESC LIMIT 200 OFFSET 0;
0|0|1|SCAN TABLE Thread-Category AS M26 USING COVERING INDEX ThreadFancyIndex
0|0|0|EXECUTE LIST SUBQUERY 1
0|1|0|SEARCH TABLE Thread USING INDEX Thread_id (id=?)
```
Test Plan: Broken!
Reviewers: evan, juan
Reviewed By: juan
Differential Revision: https://phab.nylas.com/D2869
2016-04-12 04:29:05 +08:00
|
|
|
queryable: true,
|
2016-01-26 03:11:57 +08:00
|
|
|
modelKey: 'categories'
|
perf(db): Use subselect to improve thread list query perf (53%!)
Summary:
- Use a sub-select query with much better performance to display the thread list
- Perform analyze on tables after launch
The new query is:
```
SELECT `Thread`.`data` FROM `Thread` WHERE `Thread`.`id` IN (SELECT `id` FROM `ThreadCategory` AS `M26` WHERE `M26`.`value` IN ('9m9ks71k06n5rmx82kgues09p','9s9k25q6j1krjgpkovbcjm7d','13b7ufruoymvih07ki0uahlto','dtmhlzz6phr47zp512knhjgf8','16dvjb84bszfh15kgfrjj37i3','aclwmgncdqjfibp51bvgbeik','17qad7jhbp6tozog3klm5zagt','4x4bkbawiq825u4eu3aus8tll','7axr9f5f1lzpwm2rw2ghkirhq','dsnn660af0pmou2gg3nstga8a','361qr5rva1ieby2r0ec3sn0bm','10fyvba7pjyjgeyr5i65i1zri') AND `M26`.`in_all_mail` = 1 ORDER BY `M26`.`last_message_received_timestamp` DESC LIMIT 200 OFFSET 0) ORDER BY `Thread`.`last_message_received_timestamp` DESC;
`
0|0|0|SEARCH TABLE Thread USING INDEX Thread_id (id=?)
0|0|0|EXECUTE LIST SUBQUERY 1
1|0|0|SCAN TABLE Thread-Category AS M26 USING COVERING INDEX ThreadFancyIndex
1|0|0|EXECUTE LIST SUBQUERY 2
0|0|0|USE TEMP B-TREE FOR (only on 200 result items)
```
Which is twice as performant as:
```
SELECT `Thread`.`data` FROM `Thread` INNER JOIN `ThreadCategory` AS `M26` ON `M26`.`id` = `Thread`.`id` WHERE `M26`.`value` IN ('9m9ks71k06n5rmx82kgues09p','9s9k25q6j1krjgpkovbcjm7d','13b7ufruoymvih07ki0uahlto','dtmhlzz6phr47zp512knhjgf8','16dvjb84bszfh15kgfrjj37i3','aclwmgncdqjfibp51bvgbeik','17qad7jhbp6tozog3klm5zagt','4x4bkbawiq825u4eu3aus8tll','7axr9f5f1lzpwm2rw2ghkirhq','361qr5rva1ieby2r0ec3sn0bm','10fyvba7pjyjgeyr5i65i1zri') AND `M26`.`in_all_mail` = 1 ORDER BY `M26`.`last_message_received_timestamp` DESC LIMIT 200 OFFSET 0;
0|0|1|SCAN TABLE Thread-Category AS M26 USING COVERING INDEX ThreadFancyIndex
0|0|0|EXECUTE LIST SUBQUERY 1
0|1|0|SEARCH TABLE Thread USING INDEX Thread_id (id=?)
```
Test Plan: Broken!
Reviewers: evan, juan
Reviewed By: juan
Differential Revision: https://phab.nylas.com/D2869
2016-04-12 04:29:05 +08:00
|
|
|
itemClass: Category,
|
|
|
|
joinOnField: 'id',
|
|
|
|
joinQueryableBy: ['other'],
|
2015-06-26 22:42:41 +08:00
|
|
|
|
|
|
|
TestModel.configureWithJoinedDataAttribute = ->
|
|
|
|
TestModel.attributes =
|
|
|
|
'id': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'id'
|
2015-08-29 02:12:53 +08:00
|
|
|
'clientId': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'clientId'
|
|
|
|
jsonKey: 'client_id'
|
2017-06-25 11:03:35 +08:00
|
|
|
'serverId': Attributes.String
|
2015-08-29 02:12:53 +08:00
|
|
|
queryable: true
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
2015-06-26 22:42:41 +08:00
|
|
|
'body': Attributes.JoinedData
|
|
|
|
modelTable: 'TestModelBody'
|
|
|
|
modelKey: 'body'
|
|
|
|
|
|
|
|
|
|
|
|
TestModel.attributes =
|
|
|
|
'id': Attributes.String
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'id'
|
2015-08-29 02:12:53 +08:00
|
|
|
'clientId': Attributes.String
|
|
|
|
modelKey: 'clientId'
|
|
|
|
jsonKey: 'client_id'
|
2017-06-25 11:03:35 +08:00
|
|
|
'serverId': Attributes.String
|
2015-08-29 02:12:53 +08:00
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
2015-06-26 22:42:41 +08:00
|
|
|
'body': Attributes.JoinedData
|
|
|
|
modelTable: 'TestModelBody'
|
|
|
|
modelKey: 'body'
|
|
|
|
|
|
|
|
module.exports = TestModel
|