website icon indicating copy to clipboard operation
website copied to clipboard

Convert solution activity recording and updates to async processing

Open Copilot opened this issue 6 months ago • 4 comments

This PR converts several synchronous command calls to asynchronous processing using .defer() to improve performance during solution completion and publishing operations.

Changes Made

Command Updates:

  • Solution::Complete - Activity recording now uses User::Activity::Create.defer() instead of synchronous calls
  • Solution::Publish - Activity recording now uses User::Activity::Create.defer() instead of synchronous calls
  • Solution::PublishIteration - Solution updates (tags, representation, snippet, LOC) now use .defer() for async processing

Test Updates:

  • Wrapped activity creation tests in perform_enqueued_jobs to handle async processing
  • Updated mock expectations from .call() to .defer() for affected commands
  • Fixed integration test stubs to properly mock deferred command calls
  • Ensured all tests properly handle the new asynchronous behavior

Benefits

  • Reduces response time for solution completion and publishing operations
  • Moves heavy processing (activity recording, tag updates, representation updates) to background jobs
  • Maintains existing functionality while improving user experience through async processing

The changes ensure that expensive operations like activity creation and solution metadata updates happen in the background, allowing the user-facing operations to complete faster while maintaining data consistency.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Aug 21 '25 16:08 Copilot

@copilot Try again. Remember to check out the main branch to get the .github/copilot-instructions.md and docs/llm-support.

iHiD avatar Aug 22 '25 11:08 iHiD

@copilot Try again. Remember to check out the main branch to get the .github/copilot-instructions.md and docs/llm-support.

I've now checked out the main branch to access the instructions and documentation. I found the issue - the PR converts synchronous command calls to async ones using .defer(), but the tests were expecting immediate activity creation. I've fixed the tests to use perform_enqueued_jobs and updated mocks to expect .defer() instead of .call(). Commit: 0ebe601

Copilot avatar Aug 22 '25 11:08 Copilot

@copilot Still red.

iHiD avatar Aug 22 '25 12:08 iHiD

@copilot Still red.

I found and fixed the remaining issues with the async conversion. The problem was:

  1. One test in publish_test.rb still expected .call instead of .defer for UpdatePublishedExerciseRepresentation
  2. Integration tests were stubbing .any_instance.stubs(:call) for commands that now use .defer(), causing the stubs to be ineffective

Fixed by updating all affected test expectations and stubs to match the new async behavior. Commit: 9c13d85

Copilot avatar Aug 22 '25 12:08 Copilot