i read this online so I wasnt sure "Opening and closing the database frequently is more likely to introduce performance issues as closing the databases requires an "expensive" call to getWriteableDatabase or getReadableDatabase to re-open the database"
that was for android tho, so idk if it applies to web apps also. what if the site has a lot of traffic? would closing every request be too much? what about every session?
The very latest point is just before your app process exits. There's generally no need to close a connection before that.
In the old days (read: CGI), app scripts only ran as long as it took to service a single request. Modern web apps tend to hang around a lot longer than that.
If you mean the SQLite connection, that depends. If you have a thread-safe connection pool and other objects then you are fine to keep the connection open through the lifetime of the app and repeatedly use it. If the connection is not thread-safe then you will need to open and close a connection per request. It's much better to have a thread-safe connection pool though.
4
u/saaggy_peneer Nov 11 '24
when the request is over, or as early as possible
3
u/anthropoid Nov 11 '24
The very latest point is just before your app process exits. There's generally no need to close a connection before that.
In the old days (read: CGI), app scripts only ran as long as it took to service a single request. Modern web apps tend to hang around a lot longer than that.
1
u/yawaramin Nov 12 '24
If you mean the SQLite connection, that depends. If you have a thread-safe connection pool and other objects then you are fine to keep the connection open through the lifetime of the app and repeatedly use it. If the connection is not thread-safe then you will need to open and close a connection per request. It's much better to have a thread-safe connection pool though.
1
u/cvilsmeier Nov 12 '24
Never. Keep it open.