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

Unable to Delete Database #142

Open
ghost opened this issue Apr 4, 2020 · 6 comments
Open

Unable to Delete Database #142

ghost opened this issue Apr 4, 2020 · 6 comments
Assignees

Comments

@ghost
Copy link

ghost commented Apr 4, 2020

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.

@dvassallo
Copy link
Member

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.

@ghost
Copy link
Author

ghost commented Apr 4, 2020

Makes sense, and thanks. That's what I'll do for now.

@Fubinator
Copy link
Contributor

@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.

@j-berman
Copy link
Collaborator

j-berman commented Jan 6, 2022

@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 new deleted flag with the date (no need to mark all other "share-DBS" referred to as userDbs in the server-side code for deletion). In purge.js, there should be a new scanForDeletedDatabases function that follows scanForDeletedUsers, scanForDeletedApps etc. Note there is a useful purgeTransactions 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 over Connections.sockets[databaseId] and mark them closed such that isDatabaseOpen will return false for users accessing the database (see closeUsersConnectedClients 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.

@coderfin
Copy link

@j-berman
Any update on this?

@j-berman
Copy link
Collaborator

Unfortunately not :/ this likely won't get implemented in the foreseeable future unless we get a PR from someone. I have a few things I still want to implement for Userbase I put at a higher priority and don't have much bandwidth at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants