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

Is there a bulk delete operation? #258

Open
Inversion-des opened this issue Apr 5, 2023 · 2 comments
Open

Is there a bulk delete operation? #258

Inversion-des opened this issue Apr 5, 2023 · 2 comments
Labels

Comments

@Inversion-des
Copy link

I can see heavy disk usage when going thru all the records and deleting some records. Bulk delete could solve this problem.

@Inversion-des
Copy link
Author

Inversion-des commented Apr 5, 2023

My workaround is to add this method:

module Moneta
  module Adapters
    class Sqlite < Adapter
      def delete_many(*keys)
        keys.flatten!
        keys_cs_list = keys.map{|k| "'#{String === k ? k : Marshal.dump(k)}'" }.join(', ')
        backend.execute("delete from #{config.table} where k in (#{keys_cs_list})")
      end
    end
  end
end

and use like this:
store.adapter.delete_many :k2, :k3, 'k3'
store.adapter.delete_many [:k4, 'k4']

@asppsa asppsa added the Feature label Apr 10, 2023
@asppsa
Copy link
Collaborator

asppsa commented Apr 10, 2023

Hi, you are right we don't have a bulk delete operation at the moment. Generally, we have tried to keep the methods in the moneta spec a proper subset of those on Hash, but there's nothing I can see see in the Hash method smorgasbord for this... I think we can add something though.

I'm actually wondering if we should just amend the existing #delete method to enable it to take multiple args...

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

No branches or pull requests

2 participants