mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-09 12:51:50 +08:00
fix(db): Add index for draft count query, use sqlite timing profiler and log queries >100msec
This commit is contained in:
parent
1e22f49f43
commit
df23f567cd
3 changed files with 8 additions and 6 deletions
|
@ -160,6 +160,7 @@ class Message extends Model
|
||||||
@additionalSQLiteConfig:
|
@additionalSQLiteConfig:
|
||||||
setup: ->
|
setup: ->
|
||||||
['CREATE INDEX IF NOT EXISTS MessageListIndex ON Message(account_id, thread_id, date ASC)',
|
['CREATE INDEX IF NOT EXISTS MessageListIndex ON Message(account_id, thread_id, date ASC)',
|
||||||
|
'CREATE INDEX IF NOT EXISTS MessageListDraftIndex ON Message(account_id, draft)',
|
||||||
'CREATE UNIQUE INDEX IF NOT EXISTS MessageDraftIndex ON Message(client_id)',
|
'CREATE UNIQUE INDEX IF NOT EXISTS MessageDraftIndex ON Message(client_id)',
|
||||||
'CREATE UNIQUE INDEX IF NOT EXISTS MessageBodyIndex ON MessageBody(id)']
|
'CREATE UNIQUE INDEX IF NOT EXISTS MessageBodyIndex ON MessageBody(id)']
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,12 @@ class DatabaseStore extends NylasStore
|
||||||
@_db = new sqlite3.Database @_databasePath, mode, (err) =>
|
@_db = new sqlite3.Database @_databasePath, mode, (err) =>
|
||||||
return @_handleSetupError(err) if err
|
return @_handleSetupError(err) if err
|
||||||
ready()
|
ready()
|
||||||
|
@_db.on 'profile', (query, msec) =>
|
||||||
|
if msec > 100
|
||||||
|
@_prettyConsoleLog("#{msec}msec: #{query}")
|
||||||
|
else
|
||||||
|
console.debug(DEBUG_TO_LOG, "#{msec}: #{query}")
|
||||||
|
|
||||||
|
|
||||||
_checkDatabaseVersion: ({allowNotSet} = {}, ready) =>
|
_checkDatabaseVersion: ({allowNotSet} = {}, ready) =>
|
||||||
@_db.get 'PRAGMA user_version', (err, {user_version}) =>
|
@_db.get 'PRAGMA user_version', (err, {user_version}) =>
|
||||||
|
@ -232,14 +238,9 @@ class DatabaseStore extends NylasStore
|
||||||
@_db.serialize() if @_inflightTransactions is 0
|
@_db.serialize() if @_inflightTransactions is 0
|
||||||
@_inflightTransactions += 1
|
@_inflightTransactions += 1
|
||||||
|
|
||||||
start = Date.now()
|
|
||||||
@_db[fn] query, values, (err, results) =>
|
@_db[fn] query, values, (err, results) =>
|
||||||
if err
|
if err
|
||||||
console.error("DatabaseStore: Query #{query}, #{JSON.stringify(values)} failed #{err.toString()}")
|
console.error("DatabaseStore: Query #{query}, #{JSON.stringify(values)} failed #{err.toString()}")
|
||||||
else
|
|
||||||
duration = Date.now() - start
|
|
||||||
metadata = {duration: duration, resultLength: results?.length}
|
|
||||||
console.debug(DEBUG_TO_LOG, "DatabaseStore: END (#{duration}) #{query}", metadata)
|
|
||||||
|
|
||||||
if query is COMMIT
|
if query is COMMIT
|
||||||
@_inflightTransactions -= 1
|
@_inflightTransactions -= 1
|
||||||
|
|
|
@ -175,7 +175,7 @@ class MessageStore extends NylasStore
|
||||||
if @_thread.unread
|
if @_thread.unread
|
||||||
markAsReadDelay = atom.config.get('core.reading.markAsReadDelay')
|
markAsReadDelay = atom.config.get('core.reading.markAsReadDelay')
|
||||||
setTimeout =>
|
setTimeout =>
|
||||||
return unless loadedThreadId is @_thread?.id
|
return unless loadedThreadId is @_thread?.id and @_thread.unread
|
||||||
t = new ChangeUnreadTask(thread: @_thread, unread: false)
|
t = new ChangeUnreadTask(thread: @_thread, unread: false)
|
||||||
t.canBeUndone = => false
|
t.canBeUndone = => false
|
||||||
Actions.queueTask(t)
|
Actions.queueTask(t)
|
||||||
|
|
Loading…
Add table
Reference in a new issue