Mailspring/internal_packages/developer-bar/lib/developer-bar.cjsx
Ben Gotow 8d6dcfe549 perf(thread-list): Tailored SQLite indexes, ListTabular / ScrollRegion optimizations galore
Summary:
Allow Database models to create indexes, but don't autocreate bad ones

fix minor bug in error-reporter

Fix index on message list to make thread list lookups use proper index

Developer bar ignores state changes unless it's open

DatabaseView now asks for metadata for a set of items rather than calling a function for every item. Promise.props was cute but we really needed to make a single database query for all message metadata.

New "in" matcher so you can say `thread_id IN (1,2,3)`

Add .scroll-region-content-inner which is larger than the viewport by 1 page size, and uses transform(0,0,0) trick

ScrollRegion exposes `onScrollEnd` so listTabular, et al don't need to re-implement it with more timers. Also removing requestAnimationFrame which was causing us to request scrollTop when it was not ready, and caching the values of...

...clientHeight/scrollHeight while scrolling is in-flight

Updating rendered content 10 rows at a time (RangeChunkSize) was a bad idea. Instead, add every row in a render: pass as it comes in (less work all the time vs more work intermittently). Also remove bad requestAnimationFrame, and prevent calls to...

...updateRangeState from triggering additional calls to updateRangeState by removing `componentDidUpdate => updateRangeState `

Turning off hover (pointer-events:none) is now standard in ScrollRegion

Loading text in the scroll tooltip, instead of random date shown

Handle query parse errors by catching error and throwing a better more explanatory error

Replace "quick action" retina images with background images to make React render easier

Replace hasTagId with a faster implementation which doesn't call functions and doesn't build a temporary array

Print query durations when printing to console instead of only in metadata

Remove headers from support from ListTabular, we'll never use it

Making columns part of state was a good idea but changing the array causes the entire ListTabular to re-render.  To avoid this, be smarter about updating columns. This logic could potentially go in `componentDidReceiveProps` too.

Fix specs and add 6 more for new database store functionality

Test Plan: Run 6 new specs. More in the works?

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D1651
2015-06-17 20:12:48 -07:00

172 lines
5.8 KiB
CoffeeScript

_ = require 'underscore'
React = require 'react/addons'
{DatabaseStore,
NamespaceStore,
TaskQueue,
Actions,
Contact,
Message} = require 'nylas-exports'
{ResizableRegion} = require 'nylas-component-kit'
DeveloperBarStore = require './developer-bar-store'
DeveloperBarTask = require './developer-bar-task'
DeveloperBarCurlItem = require './developer-bar-curl-item'
DeveloperBarLongPollItem = require './developer-bar-long-poll-item'
DeveloperBarClosedHeight = 30
class DeveloperBar extends React.Component
@displayName: "DeveloperBar"
@containerRequired: false
constructor: (@props) ->
@state = _.extend @_getStateFromStores(),
height: DeveloperBarClosedHeight
section: 'curl'
filter: ''
componentDidMount: =>
@taskQueueUnsubscribe = TaskQueue.listen @_onChange
@activityStoreUnsubscribe = DeveloperBarStore.listen @_onChange
componentWillUnmount: =>
@taskQueueUnsubscribe() if @taskQueueUnsubscribe
@activityStoreUnsubscribe() if @activityStoreUnsubscribe
render: =>
# TODO WARNING: This 1px height is necessary to fix a redraw issue in the thread
# list in Chrome 42 (Electron 0.26.0). Do not remove unless you've verified that
# scrolling works fine now and repaints aren't visible.
return <div style={height:1}></div> unless @state.visible
<ResizableRegion className="developer-bar"
initialHeight={@state.height}
minHeight={DeveloperBarClosedHeight}
handle={ResizableRegion.Handle.Top}>
<div className="controls">
{@_caret()}
<div className="btn-container pull-left">
<div className="btn" onClick={ => @_onExpandSection('queue')}>
<span>Queue Length: {@state.queue?.length}</span>
</div>
</div>
<div className="btn-container pull-left">
<div className="btn" onClick={ => @_onExpandSection('long-polling')}>
<div className={"activity-status-bubble state-" + @state.longPollState}></div>
<span>Long Polling: {@state.longPollState}</span>
</div>
</div>
<div className="btn-container pull-left">
<div className="btn" onClick={ => @_onExpandSection('curl')}>
<span>Requests: {@state.curlHistory.length}</span>
</div>
</div>
<div className="btn-container pull-right">
<div className="btn" onClick={Actions.sendFeedback}>Feedback</div>
</div>
<div className="btn-container pull-right">
<div className="btn" onClick={@_onToggleRegions}>Component Regions</div>
</div>
</div>
{@_sectionContent()}
<div className="footer">
<div className="btn" onClick={@_onClear}>Clear</div>
<input className="filter" placeholder="Filter..." value={@state.filter} onChange={@_onFilter} />
</div>
</ResizableRegion>
_caret: =>
if @state.height > DeveloperBarClosedHeight
<i className="fa fa-caret-square-o-down" onClick={@_onHide}></i>
else
<i className="fa fa-caret-square-o-up" onClick={@_onShow}></i>
_sectionContent: =>
expandedDiv = <div></div>
matchingFilter = (item) =>
return true if @state.filter is ''
return JSON.stringify(item).indexOf(@state.filter) >= 0
if @state.section == 'curl'
itemDivs = @state.curlHistory.filter(matchingFilter).map (item) ->
<DeveloperBarCurlItem item={item} key={item.id}/>
expandedDiv = <div className="expanded-section curl-history">{itemDivs}</div>
else if @state.section == 'long-polling'
itemDivs = @state.longPollHistory.filter(matchingFilter).map (item) ->
<DeveloperBarLongPollItem item={item} key={item.cursor}/>
expandedDiv = <div className="expanded-section long-polling">{itemDivs}</div>
else if @state.section == 'queue'
queue = @state.queue.filter(matchingFilter)
queueDivs = for i in [@state.queue.length - 1..0] by -1
task = @state.queue[i]
<DeveloperBarTask task={task}
key={task.id}
type="queued" />
queueCompleted = @state.completed.filter(matchingFilter)
queueCompletedDivs = for i in [@state.completed.length - 1..0] by -1
task = @state.completed[i]
<DeveloperBarTask task={task}
key={task.id}
type="completed" />
expandedDiv =
<div className="expanded-section queue">
<div className="btn queue-buttons"
onClick={@_onDequeueAll}>Remove Queued Tasks</div>
<div className="section-content">
{queueDivs}
<hr />
{queueCompletedDivs}
</div>
</div>
expandedDiv
_onChange: =>
# The developer bar is hidden almost all the time. Rather than render when
# API requests come in, etc., just ignore changes from our store and retrieve
# state when we open.
if @state.visible and @state.height > DeveloperBarClosedHeight
@setState(@_getStateFromStores())
_onClear: =>
Actions.clearDeveloperConsole()
_onFilter: (ev) =>
@setState(filter: ev.target.value)
_onDequeueAll: =>
Actions.dequeueAllTasks()
_onHide: =>
@setState
height: DeveloperBarClosedHeight
_onShow: =>
@setState(@_getStateFromStores())
@setState(height: 200) if @state.height < 100
_onExpandSection: (section) =>
@setState(@_getStateFromStores())
@setState(section: section)
@_onShow()
_onToggleRegions: =>
Actions.toggleComponentRegions()
_getStateFromStores: =>
visible: DeveloperBarStore.visible()
queue: TaskQueue._queue
completed: TaskQueue._completed
curlHistory: DeveloperBarStore.curlHistory()
longPollHistory: DeveloperBarStore.longPollHistory()
longPollState: DeveloperBarStore.longPollState()
module.exports = DeveloperBar