2016-01-26 03:11:57 +08:00
|
|
|
Category = require '../../src/flux/models/category'
|
2015-06-26 22:42:41 +08:00
|
|
|
Model = require '../../src/flux/models/model'
|
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'
|
|
|
|
|
|
|
|
'serverId': Attributes.ServerId
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
|
|
|
|
2015-06-26 22:42:41 +08:00
|
|
|
TestModel.configureBasic = ->
|
|
|
|
TestModel.additionalSQLiteConfig = undefined
|
|
|
|
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'
|
|
|
|
'serverId': Attributes.ServerId
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
2015-06-26 22:42:41 +08:00
|
|
|
|
|
|
|
TestModel.configureWithAllAttributes = ->
|
|
|
|
TestModel.additionalSQLiteConfig = undefined
|
|
|
|
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.additionalSQLiteConfig = undefined
|
|
|
|
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'
|
|
|
|
'serverId': Attributes.ServerId
|
|
|
|
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.additionalSQLiteConfig = undefined
|
|
|
|
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'
|
|
|
|
'serverId': Attributes.ServerId
|
|
|
|
queryable: true
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
2015-06-26 22:42:41 +08:00
|
|
|
'body': Attributes.JoinedData
|
|
|
|
modelTable: 'TestModelBody'
|
|
|
|
modelKey: 'body'
|
|
|
|
|
|
|
|
|
|
|
|
TestModel.configureWithAdditionalSQLiteConfig = ->
|
|
|
|
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'
|
|
|
|
'serverId': Attributes.ServerId
|
|
|
|
modelKey: 'serverId'
|
|
|
|
jsonKey: 'server_id'
|
2015-06-26 22:42:41 +08:00
|
|
|
'body': Attributes.JoinedData
|
|
|
|
modelTable: 'TestModelBody'
|
|
|
|
modelKey: 'body'
|
|
|
|
TestModel.additionalSQLiteConfig =
|
|
|
|
setup: ->
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
['CREATE INDEX IF NOT EXISTS ThreadListIndex ON Thread(last_message_received_timestamp DESC, account_id, id)']
|
2015-06-26 22:42:41 +08:00
|
|
|
|
|
|
|
module.exports = TestModel
|