big_query_log_viewer 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17a29b46f3220758313a6bf0cb6fe524c3fe0168
4
- data.tar.gz: dedd7319c2c1e726602233671e2d135a8375ce1f
3
+ metadata.gz: 9f22beb4892678ca9179a228569f982a43ca7a3a
4
+ data.tar.gz: f4d44663772b7cf8a52919f68549ad6ba18b1761
5
5
  SHA512:
6
- metadata.gz: c42a7c2835fec5461285f021facac417b1549c0847544e81bda46ef16a70def34e4eac5233c1ed563ebd2e32d6bbb0cc3b5b2cf2cfc6442e2b6d30165f647e21
7
- data.tar.gz: 29566331fb708b406c24fc4a3bfbebc309f211289c530bc615d30529715b682a457fc548cec9397b0e585f6bead7395e3cfc05515628f4bb17692780f51a8f64
6
+ metadata.gz: 97d8a613b0b9f2549a5584cd576a71a081b46fb84717dc83ecc8909be0bea28ead351dc1900837bc0ae567c3708aa590392a9541449ace4ed96164ea50e27d7e
7
+ data.tar.gz: 11d826779a401d3e3e5284a6f2632818324b9c0bf747bb55ec26774d225ae460c7e6bc5da822df0bd7207ff3a0c037b76228a1585f1d3032969ecdf3a656abe6
@@ -10,14 +10,24 @@ Row = BigQueryLogViewer.Row
10
10
 
11
11
  BigQueryLogViewer.Tab = React.createClass
12
12
  getInitialState: ->
13
+ pages = []
14
+ if @resultsTab()
15
+ rows = @props.tab.rowData
16
+ while rows.length >= @props.rowsPerPage
17
+ pages.push rows.splice(0, @props.rowsPerPage)
18
+ pages.push(rows) unless rows.length is 0
19
+ else
20
+ pages = [@props.tab.rowData]
13
21
  {
14
- pages: [@props.tab.rowData]
22
+ pages: pages
15
23
  activePageIndex: 0
16
24
  pageToken: @props.tab.pageToken
17
25
  showPrevLink: true
18
26
  showNextLink: true
19
27
  currentNextPage: 0
20
28
  currentPrevPage: 0
29
+ storedNextRows: []
30
+ storedPrevRows: []
21
31
  }
22
32
 
23
33
  resultsTab: ->
@@ -41,7 +51,7 @@ BigQueryLogViewer.Tab = React.createClass
41
51
  @setState(activePageIndex: @state.activePageIndex + 1)
42
52
  else if @resultsTab()
43
53
  # Else load next page from Google.
44
- @props.query.executeListQuery({pageToken: @state.pageToken, jobId: @props.tab.jobId}, (response) =>
54
+ @props.query.executeListQuery({pageToken: @state.pageToken, jobId: @props.tab.jobId, maxResults: 1000}, (response) =>
45
55
  rows =
46
56
  for r in response.rows
47
57
  {
@@ -52,7 +62,9 @@ BigQueryLogViewer.Tab = React.createClass
52
62
  severity: r.f[2].v
53
63
  msg: r.f[5].v
54
64
  }
55
- @state.pages.push(rows)
65
+ while rows.length >= @props.rowsPerPage
66
+ @state.pages.push(rows.splice(0, @props.rowsPerPage))
67
+ @state.pages.push rows unless rows.length is 0
56
68
  @setState(
57
69
  pageToken: response.pageToken
58
70
  activePageIndex: @state.activePageIndex + 1
@@ -64,117 +76,145 @@ BigQueryLogViewer.Tab = React.createClass
64
76
  alert 'Error loading more rows; check console for more information'
65
77
  )
66
78
  else if @expansionTab()
67
- # Load additional context.
68
- startRow = @props.tab.row.rid + @props.rowsPerPage / 2 + @state.currentNextPage * @props.rowsPerPage
69
- endRow = @props.tab.row.rid + @props.rowsPerPage / 2 + (@state.currentNextPage + 1) * @props.rowsPerPage
70
-
71
- # Construct query.
72
- conds = [
73
- {
74
- field: 'host'
75
- method: 'equals'
76
- type: 'string'
77
- value: @props.tab.row.host
78
- }
79
- {
80
- field: 'pid'
81
- method: 'equals'
82
- type: 'int'
83
- value: @props.tab.row.pid
84
- }
85
- {
86
- field: 'rid'
87
- method: 'between'
88
- firstValue: startRow
89
- secondValue: endRow
90
- }
91
- ]
92
- query = @props.query.buildQuery(@props.tab.source.startDate, @props.tab.source.endDate, conds, 'ts, rid desc')
93
-
94
- @props.query.executeQuery(query, {maxResults: @props.rowsPerPage}, (response) =>
95
- # Mark no more next if there were no results.
96
- if parseInt(response.totalRows) == 0
97
- @setState(showNextLink: false)
98
- return
99
-
100
- # Create new page for the expansion.
101
- rows =
102
- for r in response.rows
103
- {
104
- timestamp: new Date(1000 * r.f[0].v)
105
- host: r.f[4].v
106
- pid: r.f[3].v
107
- rid: parseInt(r.f[1].v)
108
- severity: r.f[2].v
109
- msg: r.f[5].v
110
- }
111
-
112
- @state.pages[0] = @state.pages[0].concat(rows)
113
- @setState(currentNextPage: @state.currentNextPage + 1)
114
-
115
- , (reponse) =>
116
- console.log "ERROR: #{response.message}; entire response follows"
117
- console.log response
118
- alert 'Error finding more context; check console for more information'
119
- )
79
+ if @state.storedNextRows.length > 0
80
+ # If context already loaded, just concat the rows.
81
+ pages = @state.pages.slice()
82
+ pages[0] = pages[0].concat(@state.storedNextRows.splice(0, @props.rowsPerPage))
83
+ @setState(pages: pages)
84
+ else
85
+ # Load additional context.
86
+ startRow = @props.tab.row.rid + @props.rowsPerPage / 2 + 1 + @state.currentNextPage * 1000
87
+ endRow = @props.tab.row.rid + @props.rowsPerPage / 2 + 1 + (@state.currentNextPage + 1) * 1000
88
+
89
+ # Construct query.
90
+ conds = [
91
+ {
92
+ field: 'host'
93
+ method: 'equals'
94
+ type: 'string'
95
+ value: @props.tab.row.host
96
+ }
97
+ {
98
+ field: 'pid'
99
+ method: 'equals'
100
+ type: 'int'
101
+ value: @props.tab.row.pid
102
+ }
103
+ {
104
+ field: 'rid'
105
+ method: 'between'
106
+ firstValue: startRow
107
+ secondValue: endRow
108
+ }
109
+ ]
110
+ query = @props.query.buildQuery(@props.tab.source.startDate, @props.tab.source.endDate, conds, 'ts, rid desc')
111
+
112
+ @props.query.executeQuery(query, {maxResults: 1000}, (response) =>
113
+ # Mark no more next if there were no results.
114
+ if parseInt(response.totalRows) == 0
115
+ @setState(showNextLink: false)
116
+ return
117
+ if parseInt(response.totalRows) < @props.rowsPerPage
118
+ @setState(showNextLink: false)
119
+
120
+ # Create new page for the expansion.
121
+ rows =
122
+ for r in response.rows
123
+ {
124
+ timestamp: new Date(1000 * r.f[0].v)
125
+ host: r.f[4].v
126
+ pid: r.f[3].v
127
+ rid: parseInt(r.f[1].v)
128
+ severity: r.f[2].v
129
+ msg: r.f[5].v
130
+ }
131
+
132
+ if rows.length > @props.rowsPerPage
133
+ @state.pages[0] = @state.pages[0].concat(rows.splice(0, @props.rowsPerPage))
134
+ @state.storedNextRows = rows
135
+ else
136
+ @state.pages[0] = @state.pages[0].concat(rows)
137
+
138
+ @setState(currentNextPage: @state.currentNextPage + 1)
139
+
140
+ , (reponse) =>
141
+ console.log "ERROR: #{response.message}; entire response follows"
142
+ console.log response
143
+ alert 'Error finding more context; check console for more information'
144
+ )
120
145
 
121
146
  handlePrevPage: ->
122
147
  if @resultsTab()
123
148
  @setState(activePageIndex: @state.activePageIndex - 1)
124
149
  else if @expansionTab()
125
- # Load additional context.
126
- startRow = @props.tab.row.rid - @props.rowsPerPage / 2 - @state.currentPrevPage * @props.rowsPerPage
127
- endRow = @props.tab.row.rid - @props.rowsPerPage / 2 - (@state.currentPrevPage + 1) * @props.rowsPerPage
128
-
129
- # Construct query.
130
- conds = [
131
- {
132
- field: 'host'
133
- method: 'equals'
134
- type: 'string'
135
- value: @props.tab.row.host
136
- }
137
- {
138
- field: 'pid'
139
- method: 'equals'
140
- type: 'int'
141
- value: @props.tab.row.pid
142
- }
143
- {
144
- field: 'rid'
145
- method: 'between'
146
- firstValue: endRow
147
- secondValue: startRow
148
- }
149
- ]
150
- query = @props.query.buildQuery(@props.tab.source.startDate, @props.tab.source.endDate, conds, 'ts, rid desc')
151
-
152
- @props.query.executeQuery(query, {maxResults: @props.rowsPerPage}, (response) =>
153
- # Mark no more prev if there were no results.
154
- if parseInt(response.totalRows) == 0
155
- @setState(showPrevLink: false)
156
- return
157
-
158
- # Create new page for the expansion.
159
- rows =
160
- for r in response.rows
161
- {
162
- timestamp: new Date(1000 * r.f[0].v)
163
- host: r.f[4].v
164
- pid: r.f[3].v
165
- rid: parseInt(r.f[1].v)
166
- severity: r.f[2].v
167
- msg: r.f[5].v
168
- }
150
+ if @state.storedPrevRows.length > 0
151
+ # If context already loaded, just concat the rows.
152
+ pages = @state.pages.slice()
153
+ pages[0] = @state.storedPrevRows.splice(-@props.rowsPerPage, @props.rowsPerPage).concat(pages[0])
154
+ @setState(pages: pages)
169
155
 
170
- @state.pages[0] = rows.concat(@state.pages[0])
171
- @setState(currentPrevPage: @state.currentPrevPage + 1)
172
-
173
- , (reponse) =>
174
- console.log "ERROR: #{response.message}; entire response follows"
175
- console.log response
176
- alert 'Error finding more context; check console for more information'
177
- )
156
+ else
157
+ # Load additional context.
158
+ startRow = @props.tab.row.rid - @props.rowsPerPage / 2 - 1 - @state.currentPrevPage * 1000
159
+ endRow = @props.tab.row.rid - @props.rowsPerPage / 2 - 1 - (@state.currentPrevPage + 1) * 1000
160
+
161
+ # Construct query.
162
+ conds = [
163
+ {
164
+ field: 'host'
165
+ method: 'equals'
166
+ type: 'string'
167
+ value: @props.tab.row.host
168
+ }
169
+ {
170
+ field: 'pid'
171
+ method: 'equals'
172
+ type: 'int'
173
+ value: @props.tab.row.pid
174
+ }
175
+ {
176
+ field: 'rid'
177
+ method: 'between'
178
+ firstValue: endRow
179
+ secondValue: startRow
180
+ }
181
+ ]
182
+ query = @props.query.buildQuery(@props.tab.source.startDate, @props.tab.source.endDate, conds, 'ts, rid desc')
183
+
184
+ @props.query.executeQuery(query, {maxResults: 1000}, (response) =>
185
+ # Mark no more prev if there were no results.
186
+ if parseInt(response.totalRows) == 0
187
+ @setState(showPrevLink: false)
188
+ return
189
+ if parseInt(response.totalRows) < @props.rowsPerPage
190
+ @setState(showPrevLink: false)
191
+
192
+ # Create new page for the expansion.
193
+ rows =
194
+ for r in response.rows
195
+ {
196
+ timestamp: new Date(1000 * r.f[0].v)
197
+ host: r.f[4].v
198
+ pid: r.f[3].v
199
+ rid: parseInt(r.f[1].v)
200
+ severity: r.f[2].v
201
+ msg: r.f[5].v
202
+ }
203
+
204
+ if rows.length > @props.rowsPerPage
205
+ @state.pages[0] = rows.splice(-@props.rowsPerPage, @props.rowsPerPage).concat(@state.pages[0])
206
+ @state.storedPrevRows = rows
207
+ else
208
+ @state.pages[0] = rows.concat(@state.pages[0])
209
+
210
+ @state.pages[0] = rows.concat(@state.pages[0])
211
+ @setState(currentPrevPage: @state.currentPrevPage + 1)
212
+
213
+ , (reponse) =>
214
+ console.log "ERROR: #{response.message}; entire response follows"
215
+ console.log response
216
+ alert 'Error finding more context; check console for more information'
217
+ )
178
218
 
179
219
  handleShowPage: (event) ->
180
220
  @setState(activePageIndex: parseInt(event.dispatchMarker.split('pagination-link-')[1]))
@@ -18,7 +18,7 @@ Query = BigQueryLogViewer.Query
18
18
 
19
19
  BigQueryLogViewer.TabManager = React.createClass
20
20
  getInitialState: ->
21
- @query = new BigQueryLogViewer.Query(@props.projectId, @props.tablePrefix, @props.rowsPerPage)
21
+ @query = new BigQueryLogViewer.Query(@props.projectId, @props.tablePrefix)
22
22
 
23
23
  {
24
24
  tabs: []
@@ -135,7 +135,7 @@ BigQueryLogViewer.TabManager = React.createClass
135
135
  ]
136
136
  query = @query.buildQuery(@activeTab().startDate, @activeTab().endDate, conds, 'ts, rid desc')
137
137
 
138
- @query.executeQuery(query, {maxResults: 101}, (response) =>
138
+ @query.executeQuery(query, {maxResults: @props.rowsPerPage * 2 + 1}, (response) =>
139
139
  # Create new tab for the expansion.
140
140
  rows =
141
141
  for r in response.rows
@@ -1,7 +1,7 @@
1
1
  window.BigQueryLogViewer ||= {}
2
2
 
3
3
  class BigQueryLogViewer.Query
4
- constructor: (@projectId, @tablePrefix, @rowsPerPage) ->
4
+ constructor: (@projectId, @tablePrefix) ->
5
5
  #
6
6
 
7
7
  tableRange: (startDate='CURRENT_TIMESTAMP()', endDate='CURRENT_TIMESTAMP()') ->
@@ -31,7 +31,7 @@ class BigQueryLogViewer.Query
31
31
 
32
32
  executeQuery: (query, config, success, error) ->
33
33
  console.log("Executing query: #{query}")
34
- config.maxResults ?= @rowsPerPage
34
+ config.maxResults ||= 1000
35
35
  request = gapi.client.bigquery.jobs.query
36
36
  projectId: @projectId
37
37
  timeoutMs: 30000
@@ -46,7 +46,7 @@ class BigQueryLogViewer.Query
46
46
 
47
47
  executeListQuery: (config, success, error) ->
48
48
  console.log('Executing list query')
49
- config.maxResults ?= @rowsPerPage
49
+ config.maxResults ||= 1000
50
50
  request = gapi.client.bigquery.jobs.getQueryResults
51
51
  projectId: @projectId
52
52
  jobId: config.jobId
@@ -1,3 +1,3 @@
1
1
  module BigQueryLogViewer
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_query_log_viewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails