Skip to content

Fix view sync correctness, cascade delete, N+1 queries, and revert path for VSUM views#224

Merged
ma-mirzaei merged 3 commits into221-add-view-type-neojoin-filesfrom
copilot/sub-pr-223
Mar 18, 2026
Merged

Fix view sync correctness, cascade delete, N+1 queries, and revert path for VSUM views#224
ma-mirzaei merged 3 commits into221-add-view-type-neojoin-filesfrom
copilot/sub-pr-223

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 18, 2026

Several correctness and robustness issues in the VSUM views feature introduced in #221/223. Key problems: FK constraint violations on view deletion, N+1 queries when computing sync plans, revert silently wiping views, unsafe saveAll cast, and commented-out OTP email.

Correctness Fixes

  • Cascade delete: VsumViewService.delete() and deleteByVsum() now delete VsumViewMetaModel rows first. Without this, deleting a view with metamodel associations violated the FK constraint. deleteByVsum uses a single bulk DELETE ... WHERE vm.vsumView IN :views via a new @Modifying @Query.
  • Revert wipes views: VsumHistoryService.toSyncRequest() was not mapping representation.getViews()viewRequests, so every history revert synced views to an empty list. Fixed by mapping stored view snapshots back to ViewRequest objects.
  • OTP email: mailService.sendOtpMail(...) was commented out, breaking signup/resend-OTP flows. Restored.

Performance Fix

  • N+1 in buildViewSyncPlan: The old toViewKey(VsumView) called findAllByVsumView(view) per view in a loop. Replaced with a single findAllByVsumViewIn(views) fetch, then grouping by view ID in memory before building the key map.

Safety / Stability

  • Unsafe cast removed: (List<VsumViewMetaModel>) vsumViewMetaModelRepository.saveAll(...) replaced with StreamSupport.stream(...).toList().
  • Null metaModelIds: VsumViewMetaModelService.create() now short-circuits on null/empty input instead of passing null to a Spring Data ...In query (which throws on some implementations).
  • Stable metaModelIds ordering: toList() on a Set stream is nondeterministic; added .sorted() so history snapshots are stable.

Schema

  • New V9 migration: Adds UNIQUE (vsum_view_id, meta_model_id) on vsum_view_meta_model to prevent duplicate associations, plus indexes on both FK columns.

New Repository Methods

// VsumViewMetaModelRepository
List<VsumViewMetaModel> findAllByVsumViewIn(Collection<VsumView> views);

@Modifying
@Query("DELETE FROM VsumViewMetaModel vm WHERE vm.vsumView IN :views")
void deleteAllByVsumViewIn(@Param("views") Collection<VsumView> views);

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 2 commits March 18, 2026 15:14
…e, revert views, null handling, and add unique constraint

Co-authored-by: ma-mirzaei <93537795+ma-mirzaei@users.noreply.github.com>
Co-authored-by: ma-mirzaei <93537795+ma-mirzaei@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Mar 18, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-8ae5687442759038/dbs/java/working/files-to-index12290299945586561319.list --sourceArchiveDir=/tmp/codeql-scratch-8ae5687442759038/dbs/java/src --outputDir=/tmp/codeql-scratch-8ae5687442759038/dbs/java/trap/java (dns block)
  • repository.jboss.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.13/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.13/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.13 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.13/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/methodologistUI-backend/methodologistUI-backend org.codehaus.plexus.classworlds.launcher.Launcher -pl app test -q --no-transfer-progress (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Add support for VSUM views in NeoJoin files Fix view sync correctness, cascade delete, N+1 queries, and revert path for VSUM views Mar 18, 2026
Copilot AI requested a review from ma-mirzaei March 18, 2026 15:18
@ma-mirzaei ma-mirzaei marked this pull request as ready for review March 18, 2026 15:28
@ma-mirzaei ma-mirzaei merged commit 5deaf98 into 221-add-view-type-neojoin-files Mar 18, 2026
@ma-mirzaei ma-mirzaei deleted the copilot/sub-pr-223 branch March 18, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants