Skip to content

fix: resolve duplicate data, optimize csv/excel export, and fix progress bar#2015

Merged
ysfscream merged 3 commits intoemqx:mainfrom
ni00:bugfix-export-data
Apr 20, 2026
Merged

fix: resolve duplicate data, optimize csv/excel export, and fix progress bar#2015
ysfscream merged 3 commits intoemqx:mainfrom
ni00:bugfix-export-data

Conversation

@ni00
Copy link
Copy Markdown
Contributor

@ni00 ni00 commented Dec 27, 2025

Closes #2006

Problems Fixed

1. Duplicate data in JSON/YAML/XML exports

Every exported message contained all fields twice — once at the top level and again inside a properties sub-object. Root cause: entityToModel used ...entity spread into both the top-level object and properties, causing full duplication.

Fix: destructure MQTT5 property fields explicitly, spread only ...rest at the top level, and build properties from the extracted fields only.

2. Broken CSV/Excel format

  • All messages were crammed onto a single line rather than one row per message
  • Message data was dumped as raw JSON within a single field

Fix: flatten each message into individual rows with clean columns (client_id, connection_name, topic, payload, qos, retain, direction, createAt, plus MQTT5 properties). CSV writes one row per message with proper headers; Excel creates one sheet per connection with the same flat structure.

3. Inaccurate progress bar

Progress was tracked per-connection (processedConnections / totalConnections). With 1-2 connections but 150k+ messages, the bar stayed at 0% then jumped to 100%.

Fix: count total messages before export, then update progress after each batch (~1000 messages), giving smooth incremental progress across all 5 export formats.

Changed Files

  • src/database/services/ConnectionService.ts — fix entityToModel to avoid duplicating entity fields into properties
  • src/database/services/MessageService.ts — fix entityToModel/modelToEntity destructuring; add countByConnectionId()
  • src/main/streamExportData.ts — rewrite CSV/Excel export to one-row-per-message; switch progress tracking to message-level granularity

Self-tested

All cases below have been verified locally:

  • Export JSON — no duplicate properties nesting
  • Export YAML — clean flat structure
  • Export XML — no duplicate fields
  • Export CSV — one message per row, proper column headers, opens correctly in spreadsheet apps
  • Export Excel — one message per row, one sheet per connection
  • Export with large dataset (10k+ messages) — progress bar updates smoothly
  • Export with single connection — progress doesn't jump 0% → 100%

Would appreciate a second pair of eyes on these scenarios. Thanks!

@ni00 ni00 force-pushed the bugfix-export-data branch from f7d7c6c to 81e38a7 Compare December 27, 2025 17:12
@ni00 ni00 changed the title fix: resolve duplicate data and optimize CSV/Excel export fix: resolve duplicate data, optimize CSV/Excel export, and fix progress bar Feb 18, 2026
@ni00 ni00 marked this pull request as ready for review February 18, 2026 11:31
@ni00 ni00 changed the title fix: resolve duplicate data, optimize CSV/Excel export, and fix progress bar fix: resolve duplicate data, optimize csv/excel export, and fix progress bar Feb 18, 2026
@ysfscream ysfscream requested review from Copilot and ysfscream March 17, 2026 15:13
@ysfscream ysfscream self-assigned this Mar 17, 2026
@ysfscream ysfscream added enhancement New feature or request desktop MQTTX Desktop labels Mar 17, 2026
@ysfscream ysfscream moved this to In Progress in MQTTX Mar 17, 2026
@ysfscream ysfscream added this to the v1.13.1 milestone Mar 17, 2026
@ysfscream ysfscream requested a review from Red-Asuka March 17, 2026 15:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the “Export Data” workflow to eliminate duplicated MQTT5 fields in JSON/YAML/XML exports, produce usable CSV/Excel outputs (one message per row), and make the progress bar reflect message-level progress rather than connection-level progress.

Changes:

  • Refactors entityToModel / modelToEntity mappings for Connection/Message models to prevent duplicating fields into properties.
  • Reworks CSV/Excel export to emit flattened message rows (instead of embedding JSON blobs) and updates progress after each streamed batch.
  • Adds MessageService.countByConnectionId() to pre-compute total message counts for smoother progress reporting.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/main/streamExportData.ts Message-level progress tracking; CSV/Excel export rewritten to emit one row per message with flattened columns
src/database/services/MessageService.ts Fixes model/entity conversions to avoid duplicating MQTT5 props; adds countByConnectionId()
src/database/services/ConnectionService.ts Fixes connection/message mapping to avoid duplicating entity fields into properties; improves Will/MQTT5 property mapping
src/database/services/TopicNodeService.ts Import order / constructor formatting changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

private connectionRepository: Repository<ConnectionEntity>,
private messageService: MessageService,
) {}
) { }
Comment on lines 7 to 20
@@ -14,29 +16,48 @@ export default class MessageService {
// @ts-ignore
@InjectRepository(ConnectionEntity)
private connectionRepository: Repository<ConnectionEntity>,
) {}
) { }

Comment on lines 17 to 35
@@ -28,48 +31,83 @@ export default class ConnectionService {
// @ts-ignore
@InjectRepository(WillEntity)
private willRepository: Repository<WillEntity>,
) {}
) { }

Comment on lines +92 to +96
let totalMessages = 0
for (const conn of connections) {
totalMessages += await messageService.countByConnectionId(conn.id!)
}
this.totalMessages = totalMessages
Comment on lines +188 to +197
const headers = [
'client_id',
'connection_name',
'topic',
'payload',
'qos',
'retain',
'direction',
'createAt',
'payload_format_indicator',
Comment on lines +216 to +223
client_id: connection.clientId,
connection_name: connection.name,
topic: msg.topic,
payload: msg.payload, // payload is string in MessageModel
qos: msg.qos,
retain: msg.retain,
direction: msg.out ? 'publish' : 'received',
createAt: msg.createAt,
Copy link
Copy Markdown
Member

@ysfscream ysfscream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Copy link
Copy Markdown
Member

@ysfscream ysfscream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@ysfscream ysfscream merged commit b2c2dec into emqx:main Apr 20, 2026
8 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in MQTTX Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop MQTTX Desktop enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug] Various bugs with Export Data

3 participants