mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Notebooks: Greatly Reduce Time to Generate HTML Table String (#4086)
* Greatly reduce time to generate html table string * change outer tag to table instead of html * address PR feedback for more descriptive variable name
This commit is contained in:
@@ -339,7 +339,6 @@ export class SQLFuture extends Disposable implements FutureInternal {
|
|||||||
for (let resultSet of batch.resultSetSummaries) {
|
for (let resultSet of batch.resultSetSummaries) {
|
||||||
let rowCount = resultSet.rowCount > MAX_ROWS ? MAX_ROWS : resultSet.rowCount;
|
let rowCount = resultSet.rowCount > MAX_ROWS ? MAX_ROWS : resultSet.rowCount;
|
||||||
this._queryRunner.getQueryRows(0, rowCount, resultSet.batchId, resultSet.id).then(d => {
|
this._queryRunner.getQueryRows(0, rowCount, resultSet.batchId, resultSet.id).then(d => {
|
||||||
let columns = resultSet.columnInfo;
|
|
||||||
|
|
||||||
let msg: nb.IIOPubMessage = {
|
let msg: nb.IIOPubMessage = {
|
||||||
channel: 'iopub',
|
channel: 'iopub',
|
||||||
@@ -352,7 +351,7 @@ export class SQLFuture extends Disposable implements FutureInternal {
|
|||||||
output_type: 'execute_result',
|
output_type: 'execute_result',
|
||||||
metadata: {},
|
metadata: {},
|
||||||
execution_count: this._executionCount,
|
execution_count: this._executionCount,
|
||||||
data: { 'application/vnd.dataresource+json': this.convertToDataResource(columns, d), 'text/html': this.convertToHtmlTable(columns, d) }
|
data: { 'application/vnd.dataresource+json': this.convertToDataResource(resultSet.columnInfo, d), 'text/html': this.convertToHtmlTable(resultSet.columnInfo, d) }
|
||||||
},
|
},
|
||||||
metadata: undefined,
|
metadata: undefined,
|
||||||
parent_header: undefined
|
parent_header: undefined
|
||||||
@@ -374,7 +373,7 @@ export class SQLFuture extends Disposable implements FutureInternal {
|
|||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertToDataResource(columns: IDbColumn[], d: QueryExecuteSubsetResult): IDataResource {
|
private convertToDataResource(columns: IDbColumn[], subsetResult: QueryExecuteSubsetResult): IDataResource {
|
||||||
let columnsResources: IDataResourceSchema[] = [];
|
let columnsResources: IDataResourceSchema[] = [];
|
||||||
columns.forEach(column => {
|
columns.forEach(column => {
|
||||||
columnsResources.push({name: escape(column.columnName)});
|
columnsResources.push({name: escape(column.columnName)});
|
||||||
@@ -383,7 +382,7 @@ export class SQLFuture extends Disposable implements FutureInternal {
|
|||||||
columnsFields.fields = columnsResources;
|
columnsFields.fields = columnsResources;
|
||||||
return {
|
return {
|
||||||
schema: columnsFields,
|
schema: columnsFields,
|
||||||
data: d.resultSubset.rows.map(row => {
|
data: subsetResult.resultSubset.rows.map(row => {
|
||||||
let rowObject: { [key: string]: any; } = {};
|
let rowObject: { [key: string]: any; } = {};
|
||||||
row.forEach((val, index) => {
|
row.forEach((val, index) => {
|
||||||
rowObject[index] = val.displayValue;
|
rowObject[index] = val.displayValue;
|
||||||
@@ -394,29 +393,23 @@ export class SQLFuture extends Disposable implements FutureInternal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private convertToHtmlTable(columns: IDbColumn[], d: QueryExecuteSubsetResult): string {
|
private convertToHtmlTable(columns: IDbColumn[], d: QueryExecuteSubsetResult): string {
|
||||||
let data: SQLData = {
|
let htmlString = '<table>';
|
||||||
columns: columns.map(c => escape(c.columnName)),
|
if (columns.length > 0) {
|
||||||
rows: d.resultSubset.rows.map(r => r.map(c => c.displayValue))
|
htmlString += '<tr>';
|
||||||
};
|
for (let column of columns) {
|
||||||
let table: HTMLTableElement = document.createElement('table');
|
htmlString += '<th>' + escape(column.columnName) + '</th>';
|
||||||
table.createTHead();
|
|
||||||
table.createTBody();
|
|
||||||
let hrow = <HTMLTableRowElement>table.insertRow();
|
|
||||||
// headers
|
|
||||||
for (let column of data.columns) {
|
|
||||||
let cell = hrow.insertCell();
|
|
||||||
cell.innerHTML = column;
|
|
||||||
}
|
}
|
||||||
|
htmlString += '</tr>';
|
||||||
for (let row in data.rows) {
|
|
||||||
let hrow = <HTMLTableRowElement>table.insertRow();
|
|
||||||
for (let column in data.columns) {
|
|
||||||
let cell = hrow.insertCell();
|
|
||||||
cell.innerHTML = escape(data.rows[row][column]);
|
|
||||||
}
|
}
|
||||||
|
for (let row in d.resultSubset.rows) {
|
||||||
|
htmlString += '<tr>';
|
||||||
|
for (let column in columns) {
|
||||||
|
htmlString += '<td>' + escape(d.resultSubset.rows[row][column].displayValue) + '</td>';
|
||||||
}
|
}
|
||||||
let tableHtml = '<table>' + table.innerHTML + '</table>';
|
htmlString += '</tr>';
|
||||||
return tableHtml;
|
}
|
||||||
|
htmlString += '</table>';
|
||||||
|
return htmlString;
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertToDisplayMessage(msg: IResultMessage | string): nb.IIOPubMessage {
|
private convertToDisplayMessage(msg: IResultMessage | string): nb.IIOPubMessage {
|
||||||
|
|||||||
Reference in New Issue
Block a user