smallbets / userbase

Create secure and private web apps using only static JavaScript, HTML, and CSS.
https://userbase.com
MIT License
2.26k stars 124 forks source link

Unable to Delete Database #142

Open ghost opened 4 years ago

ghost commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

Fubinator commented 3 years ago

@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 commented 2 years ago

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

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 commented 1 week ago

@j-berman Any update on this?

j-berman commented 1 week ago

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