Skip to content

Commit 180f09f

Browse files
committed
fix(api): 🐛 remove duplicates in reports
1 parent 088ff8f commit 180f09f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/main/java/net/netshot/netshot/rest/RestService.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@
181181
import org.graalvm.polyglot.HostAccess.Export;
182182
import org.hibernate.HibernateException;
183183
import org.hibernate.ObjectNotFoundException;
184+
import org.hibernate.ScrollMode;
184185
import org.hibernate.ScrollableResults;
185186
import org.hibernate.query.Query;
186187
import org.hibernate.Session;
188+
import org.hibernate.StatelessSession;
187189
import org.hibernate.exception.ConstraintViolationException;
188190
import org.quartz.SchedulerException;
189191
import org.slf4j.MarkerFactory;
@@ -7939,9 +7941,14 @@ public Response getDataXLSX(@Context HttpServletRequest request,
79397941
deviceSheet.setAutoFilter(new CellRangeAddress(0, y, 0, x));
79407942
}
79417943

7942-
try (ScrollableResults<Device> scrollableDevices = deviceQuery.scroll()) {
7944+
try (ScrollableResults<Device> scrollableDevices = deviceQuery.scroll(ScrollMode.FORWARD_ONLY)) {
7945+
long previousDeviceId = -1;
79437946
while (scrollableDevices.next()) {
79447947
Device device = scrollableDevices.get();
7948+
if (device.getId() == previousDeviceId) {
7949+
continue;
7950+
}
7951+
previousDeviceId = device.getId();
79457952
int x = -1;
79467953
row = deviceSheet.createRow(++y);
79477954
row.createCell(++x).setCellValue(device.getId());
@@ -8049,8 +8056,13 @@ public Response getDataXLSX(@Context HttpServletRequest request,
80498056
}
80508057

80518058
try (ScrollableResults<NetworkInterface> scrollableNetworkInterfaces = interfaceQuery.scroll()) {
8059+
long previousNetworkInterfaceId = -1;
80528060
while (scrollableNetworkInterfaces.next()) {
80538061
NetworkInterface networkInterface = scrollableNetworkInterfaces.get();
8062+
if (networkInterface.getId() == previousNetworkInterfaceId) {
8063+
continue;
8064+
}
8065+
previousNetworkInterfaceId = networkInterface.getId();
80548066
Device device = networkInterface.getDevice();
80558067
if (networkInterface.getIpAddresses().isEmpty()) {
80568068
row = interfaceSheet.createRow(++y);
@@ -8147,8 +8159,13 @@ public Response getDataXLSX(@Context HttpServletRequest request,
81478159
inventorySheet.setAutoFilter(new CellRangeAddress(0, y, 0, x));
81488160
}
81498161
try (ScrollableResults<Module> scrollableModules = moduleQuery.scroll()) {
8162+
long previousModuleId = -1;
81508163
while (scrollableModules.next()) {
81518164
Module module = scrollableModules.get();
8165+
if (module.getId() == previousModuleId) {
8166+
continue;
8167+
}
8168+
previousModuleId = module.getId();
81528169
Device device = module.getDevice();
81538170
int x = -1;
81548171
row = inventorySheet.createRow(++y);
@@ -8221,7 +8238,6 @@ public Response getDataXLSX(@Context HttpServletRequest request,
82218238
row.getCell(x).setCellStyle(datetimeCellStyle);
82228239
row.createCell(++x).setCellValue(checkResult.getResult().toString());
82238240
}
8224-
session.clear();
82258241
}
82268242

82278243
if (exportGroups) {

0 commit comments

Comments
 (0)