userbase
userbase copied to clipboard
Unable to Delete Database
It doesn't look like there's an SDK method for deleting a database—only one for deleting individual items in batches of ten.
I'm building an RSS reader and using Userbase to sync feed subscriptions and unread articles. I thought I'd create a feeds
database and store each feed as an item in it. Like so:
userbase.insertItem({
databaseName: 'feeds',
item: {
url: feed.url,
unread: [{
date: article.date,
url: article.url,
}],
},
itemId: md5(feed.url), // MD5: 100 character limit
})
However, it's not uncommon for a user to let unread articles pile up, leading to tens or hundreds of unread. It makes sense to limit unread articles somewhat—perhaps to the most recent hundred. But the 10 KB limit on a databases items prevents me from storing even 50 unread
.
So I'm instead creating a database per feed, while storing each unread
as an individual item. I never run up against the 10 KB limit for items, of course. But it's cumbersome to clear out a feed database in batches of ten (rate-limited, of course) after a user has unsubscribed from a feed. I'd like to simply delete the database and be done.
I also wonder. Is creating a database per feed even advisable? It's the only way I can see an RSS reader existing given the 10 KB item limit. But is there a hard limit on databases per user? Because I can easily imagine users who are subscribed to a couple hundred feeds. If there is a limit, some error messaging would be helpful.
Anywho, thanks for making Userbase.
Hey, thank you for filing the issue. Deleting a database makes sense, and we'll add this to the backlog.
There is no hard limit on the number of databases, and having a database per feed sounds like the right approach for what you're doing.
You can also have another database for feed metadata, in which you'd have one record per feed. Until we support deleting a database, you may simply flag it as deleted and not show it to the user. Then once the deleteDatabase function is available, you can simply walk over the list and delete all those that are flagged for deletion. We'll try to prioritize this asap, but this can help you get unblocked.
Makes sense, and thanks. That's what I'll do for now.
@j-berman I am currently considering trying to implement this feature. Since you assigned the issue to yourself a while back, I wanted to ask if you accept PRs and think it's doable for someone with not quite the overview of the code. I've had a rough look through the code and have a few ideas on how this might work.
I would try to build the feature so that only owner can delete databases. If the owner deletes the DB, then all "Share-DBs" of this DB, are also deleted.
@Fubinator I'm sorry for the mega delayed response. Would absolutely accept PR's :) I think it's doable but there's a bit more underneath the surface that makes it trickier to handle because of the web socket, here are some pointers:
- On the server-side, a
userDb
should be marked for deletion via a newdeleted
flag with the date (no need to mark all other "share-DBS" referred to asuserDbs
in the server-side code for deletion). Inpurge.js
, there should be a newscanForDeletedDatabases
function that followsscanForDeletedUsers
,scanForDeletedApps
etc. Note there is a usefulpurgeTransactions
which will get rid of the needed data depending on whether or not the user deleting is an owner. The flow of user deletion, app deletion, and admin deletion can serve as a useful guide. - When an owner of a database deletes a database, it should also close the database for all other users accessing the database. In order to close all connections accessing the database, in the
userbase-server/ws.js
, iterate overConnections.sockets[databaseId]
and mark them closed such thatisDatabaseOpen
will return false for users accessing the database (seecloseUsersConnectedClients
as a guide). - Once an owner of a database deletes a database, the database should no longer be accessible to any users because of the
deleted
flag. - After deleting, the owner who deleted the database should be able to create a database with the same name without needing to refresh the page. This will be a bit tricky to handle client-side, which keeps track of open databases over the web socket.
Happy to accept a PR from anyone on this. I will get to it within the next 6-9 months if not. It's one of the more demanded features and I'm looking to get back into adding more features.