Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Navisworks): CNX-889 Prevent unnecessary "Save Changes" prompts in Navisworks #491

Conversation

jsdbroughton
Copy link
Contributor

@jsdbroughton jsdbroughton commented Jan 13, 2025

Prevent unnecessary "Save Changes" prompts in Navisworks

Issue

Users were prompted to save changes when closing Navisworks, even when no actual modifications had been made to the model. This was occurring because database operations were unnecessarily marking the document as modified.

Root Cause Analysis

Investigation revealed several causes:

  1. Using DatabaseChangedAction.Reset in transactions was marking the document as modified, even for read-only operations
  2. Creating transactions to check table existence was triggering the document's dirty state
  3. The table existence check was being performed with a transaction unnecessarily, even for read operations

Changes

  1. Split database operations into discrete functions:

    • DoesTableExist() - Pure read operation without transactions
    • CreateTable() - Only uses transaction when creating the table
  2. Modified database operations to minimize transactions:

    • Removed transactions entirely from read operations
    • Only use transactions when writing data
    • Changed DatabaseChangedAction.Reset to DatabaseChangedAction.Edited when modifications are needed
  3. Optimized state retrieval:

    • Removed unnecessary transaction from RetrieveStateFromDatabase()
    • Simplified table existence checking
    • Added early returns to avoid unnecessary operations
  4. Added state comparison:

    • Track the last saved state to avoid redundant saves
    • Only write to the database when the state changes

Impact

  • Users will no longer see save prompts unless actual changes have been made
  • Improved performance by reducing unnecessary database operations
  • Maintained all existing functionality while reducing false "dirty" states

Technical Details

The key discovery was that even read-only database operations using DatabaseChangedAction.Reset marked the document as modified. We now avoid transactions altogether for read operations and only use them with DatabaseChangedAction.Edited when making changes.

Testing Notes

Areas verified:

  • Opening and closing documents without changes should not prompt for save
  • Making actual changes should still prompt for save
  • Database state persistence should continue working as expected
  • State comparison should prevent unnecessary saves

- Add reference to `Autodesk.Navisworks.Api.DocumentParts.DocumentDatabase`
- Add `_lastSavedState` field to store the last saved state
- Compare current state with last saved state before saving
- Update last saved state after successful save
- Rename `ClearAndSave` method to `ClearAndSaveThisState` for clarity pseudo override
- Reset last saved state when clearing models
Copy link

linear bot commented Jan 13, 2025

@jsdbroughton jsdbroughton changed the title fix(Navisworks): CNX-889 Document dirty state no longer triggered by state reads. fix(Navisworks): CNX-889 Prevent unnecessary "Save Changes" prompts in Navisworks Jan 13, 2025
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 9.15%. Comparing base (ba0cdd3) to head (4c17ca3).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@          Coverage Diff          @@
##             dev    #491   +/-   ##
=====================================
  Coverage   9.15%   9.15%           
=====================================
  Files        228     228           
  Lines       4306    4306           
  Branches     542     542           
=====================================
  Hits         394     394           
  Misses      3896    3896           
  Partials      16      16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jsdbroughton jsdbroughton marked this pull request as ready for review January 13, 2025 20:10
@jsdbroughton jsdbroughton enabled auto-merge (squash) January 13, 2025 20:10
@jsdbroughton jsdbroughton merged commit 48670c4 into dev Jan 14, 2025
5 checks passed
@jsdbroughton jsdbroughton deleted the jonathon/cnx-889-user-is-prompted-to-save-file-on-close-even-with-no-changes branch January 14, 2025 10:52
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