-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: increase performance when exporting large datasets
increase performance by avoid calling sheet.shiftRows() by duplicating the sheet into a temporal one, exporting the data and then appending the last part of the sheet before continuing with the footers
- Loading branch information
Showing
3 changed files
with
144 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterBigDatasetDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*- | ||
* #%L | ||
* Grid Exporter Add-on | ||
* %% | ||
* Copyright (C) 2022 - 2023 Flowing Code | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
package com.flowingcode.vaadin.addons.gridexporter; | ||
|
||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
import org.apache.poi.EncryptedDocumentException; | ||
import com.flowingcode.vaadin.addons.demo.DemoSource; | ||
import com.github.javafaker.Faker; | ||
import com.vaadin.flow.component.grid.Grid; | ||
import com.vaadin.flow.component.grid.Grid.Column; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.PageTitle; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@DemoSource | ||
@PageTitle("Grid Exporter Addon Big Dataset Demo") | ||
@Route(value = "gridexporter/bigdataset", layout = GridExporterDemoView.class) | ||
@SuppressWarnings("serial") | ||
public class GridExporterBigDatasetDemo extends Div { | ||
|
||
public GridExporterBigDatasetDemo() throws EncryptedDocumentException, IOException { | ||
Grid<Person> grid = new Grid<>(Person.class); | ||
grid.removeAllColumns(); | ||
grid.setColumnReorderingAllowed(true); | ||
Column<Person> nameCol = grid.addColumn("name").setHeader("Name"); | ||
Column<Person> lastNameCol = grid.addColumn("lastName").setHeader("Last Name"); | ||
Column<Person> budgetCol = grid.addColumn(item -> "$" + item.getBudget()).setHeader("Budget"); | ||
BigDecimal[] total = new BigDecimal[1]; | ||
total[0] = BigDecimal.ZERO; | ||
List<Person> persons = | ||
IntStream.range(0, 7000) | ||
.asLongStream() | ||
.mapToObj( | ||
number -> { | ||
Faker faker = new Faker(); | ||
Double budget = faker.number().randomDouble(2, 10000, 100000); | ||
total[0] = total[0].add(BigDecimal.valueOf(budget)); | ||
budgetCol.setFooter("$" + total[0]); | ||
return new Person( | ||
faker.name().firstName(), | ||
faker.name().lastName(), | ||
faker.number().numberBetween(15, 50), | ||
budget); | ||
}).collect(Collectors.toList()); | ||
grid.setItems(query->persons.stream().skip(query.getOffset()).limit(query.getLimit())); | ||
grid.setWidthFull(); | ||
this.setSizeFull(); | ||
GridExporter<Person> exporter = GridExporter.createFor(grid); | ||
exporter.setExportValue(budgetCol, item -> "" + item.getBudget()); | ||
exporter.setColumnPosition(lastNameCol, 1); | ||
exporter.setTitle("People information"); | ||
exporter.setFileName( | ||
"GridExport" + new SimpleDateFormat("yyyyddMM").format(Calendar.getInstance().getTime())); | ||
add(grid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters