ekvedaras / laravel-query-intellij

💿 Laravel Query Builder integration for PhpStorm
MIT License
47 stars 3 forks source link

Attempt to fix UI freeze #115

Closed ekvedaras closed 2 months ago

ekvedaras commented 5 months ago

Attempting to use ReadAction.nonBlocking and Disposable

smirok commented 4 months ago
ReadAction.nonBlocking<Unit> {
     TableAndAliasCollector(this).collect()
     DbReferenceResolver(this).resolve()
}.inSmartMode(project).expireWith(expressionDisposable).executeSynchronously()

It means that the actions inside ReadAction.nonBlocking block will be executed on the current thread, therefore tests and following actions during plugin execution will wait till the end of ReadAction.nonBlocking

The tests will be passed, but make sure that

TableAndAliasCollector(this).collect()
DbReferenceResolver(this).resolve()

is an idempotent operations block, because ReadAction.nonBlocking will be restarted on any UI actions (typing, etc.)

ekvedaras commented 2 months ago

How did I miss .executeSynchronously()... 🙈

smirok commented 2 months ago

@ekvedaras Hi! The fact that this approach did not lead to the problem's fix means that you probably do not have enough cancellation points in the code (https://plugins.jetbrains.com/docs/intellij/general-threading-rules.html#read-action-cancellability). Please try to use ProgressManager.checkCanceled() between DB calls. For example, you could use it as a first command in every iteration of forEach-es in DbReferenceResolver.kt.