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 deleteDatabase blocking due to open connections #144

Merged

Conversation

janne-koschinski
Copy link
Contributor

Automatically close database connections on delete
Handle "blocked" event in deleteDatabase

@janne-koschinski janne-koschinski requested review from cedrickcooke and a team as code owners January 23, 2024 09:40
@cedrickcooke cedrickcooke added the patch Changes that should bump the PATCH version number label Jan 24, 2024
@janne-koschinski janne-koschinski force-pushed the justjanne/auto-close-on-delete branch from 06c1231 to ead7323 Compare January 26, 2024 08:47
@janne-koschinski
Copy link
Contributor Author

If there's anything we'll need to change to allow this to merge, please feel free to contact me, currently this is blocking us quite a bit :/

Copy link
Collaborator

@cedrickcooke cedrickcooke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, last week was quite busy and I had to do some research to understand exactly what was happening. The IDB event names were not intuitive to me 😅.

We don't have a public facing style guide (yet? I'll look into it apparently I was wrong, relevant portion here), but could you please replace the !! with checkNotNull? Our convention is to use !! when the value is guaranteed non-null but the compiler can't figure it out, and checkNotNull when things shouldn't be null but might be due to logic errors. I'll approve after that, thanks for handling this

@janne-koschinski janne-koschinski force-pushed the justjanne/auto-close-on-delete branch 2 times, most recently from 302a190 to 546fc9c Compare January 31, 2024 12:22
@janne-koschinski
Copy link
Contributor Author

Sorry for the delay, last week was quite busy and I had to do some research to understand exactly what was happening. The IDB event names were not intuitive to me 😅.

I was wondering if I should document them in the code, looks like I should've! Added that now.

please replace the !! with checkNotNull? Our convention is to use !! when the value is guaranteed non-null but the compiler can't figure it out, and checkNotNull when things shouldn't be null but might be due to logic errors. I'll approve after that, thanks for handling this

I hope the way I did it now is fine, adding an ensureDatabase method allows me to add some more context to the exception

internal fun ensureDatabase(): IDBDatabase = checkNotNull(database) { "database is closed" }

- Automatically close database connections on delete
- Handle "blocked" event in deleteDatabase
@janne-koschinski janne-koschinski force-pushed the justjanne/auto-close-on-delete branch from 546fc9c to 7fc7385 Compare January 31, 2024 12:24
database.addEventListener("close", { close() })
}

internal fun ensureDatabase(): IDBDatabase = checkNotNull(database) { "database is closed" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, love that it gives us a description

@cedrickcooke cedrickcooke merged commit 9102f14 into JuulLabs:main Jan 31, 2024
2 checks passed
@janne-koschinski janne-koschinski deleted the justjanne/auto-close-on-delete branch February 1, 2024 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Changes that should bump the PATCH version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants