Skip to content

feat(contacts): add ad ids column and export history to contact export - #1581

Merged
viethung0o0 merged 1 commit into
mainfrom
feat/export-contact-ad-ids
Oct 29, 2026
Merged

viethung0o0 merged 1 commit into
mainfrom
feat/export-contact-ad-ids

Conversation

@viethung0o0

@viethung0o0 viethung0o0 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The contact export has a new optional "Ad IDs" column: every ad the contact came from, oldest first, the same list as {{ad_ids}}.
  • It is off by default in the export dialog, under its own "Ads" group.
  • Ad IDs are loaded only when the column is selected, with one query per export page, so other exports are unchanged.
  • The public contacts.export API accepts it as sys:adIds.
  • {{ad_ids}} / {{ad_id}} and the export now share one query.
  • An empty ad id sent by a provider is no longer stored, listed, or shown as a nameless row in the Ads report.
  • Export history: an "Export history" button in the export dialog lists past contact exports with status, row count, who started each one and when it is deleted, and downloads any ready file with a fresh link.
  • A member sees only their own exports; the owner and members with the super admin permission see every export.
  • New public contacts.listExportFiles (GET /v1/contacts/export-files, cursor-paginated); a workspace token sees every export.
  • Contact exports are kept for 7 days. A daily job deletes the stored file, then its row. A file that cannot be deleted keeps its row and is retried the next day, without blocking newer ones.
  • The export dialog no longer hangs on "taking longer than expected": the timeout counts real polls, including failed ones.
  • Large exports: each page loads only the custom fields, tags and inbox rows its columns render (it used to load every one of each contact's).
  • A failed upload now fails the export at once; before, the job could wait on the stream forever once storage stopped reading it.
  • Export progress is saved every 5 seconds instead of after every page, and the row limit goes from 500,000 to 10,000,000 (memory stays at one page).

Deploy note

  • Migration 20261029043008_add_file_export_created_at_index builds a partial index on File("createdAt") for export rows with CREATE INDEX CONCURRENTLY (no write lock on File). The file runs unwrapped and can be re-run.

Verification

  • pnpm lint, i18n check and schema drift check
  • check-types for database, business, worker-config, worker, ai and builder
  • Unit tests for database, business, worker, cli and builder
  • Ran a real export through the worker and read the CSV
  • Checked against Postgres: the per-contact cap, repeated and tied ads, empty ad ids, and that the Ads report still uses its index
  • Applied the migration on a dev database; the index is valid and the cleanup query uses it
  • Checked against Postgres that history pages chain with microsecond cursors and that a cursor maps back to its exact row
  • Ran real exports against Postgres: every cell of the custom field, tag, Contact ID and WhatsApp User ID columns matches a direct SQL read
  • In the browser: the column shows under "Ads" and is not selected by default; the history button opens the list, Download saves the CSV, and a new export finishes without hanging

@github-actions github-actions Bot added the feature New feature or request label Oct 29, 2026
@viethung0o0
viethung0o0 force-pushed the feat/export-contact-ad-ids branch 3 times, most recently from 4647e93 to 430a576 Compare October 29, 2026 06:16
@viethung0o0 viethung0o0 changed the title feat(contacts): add an Ad IDs column to the contact export feat(contacts): add ad ids column and export history to contact export Oct 29, 2026
@viethung0o0
viethung0o0 marked this pull request as ready for review October 29, 2026 06:20
@viethung0o0
viethung0o0 force-pushed the feat/export-contact-ad-ids branch from 430a576 to 467a17f Compare October 29, 2026 07:11
- new optional Ad IDs column listing every ad a contact came from, off by default
- loaded only when selected, one query per export page
- an empty ad id is no longer stored, listed or shown in the ads report
- export history in the export dialog and a public list endpoint; members see their own exports, admins and the owner see all
- contact exports are deleted after 7 days by a daily cleanup job
- the export dialog no longer hangs while waiting for the file
- exports load only the custom fields, tags and inbox rows their columns need
- a failed upload stops the export instead of leaving the job waiting forever
- export progress is saved every 5 seconds, and the row limit is now 10 million
@viethung0o0
viethung0o0 force-pushed the feat/export-contact-ad-ids branch from 467a17f to 89d4bfc Compare October 29, 2026 07:53
@viethung0o0
viethung0o0 merged commit 098cffe into main Oct 29, 2026
14 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants