Code Monkey home page Code Monkey logo

Comments (11)

peter-wangxu avatar peter-wangxu commented on June 18, 2024

Make sense to create a set like queue for your use case.

How is your data? Is it hashable?

from persist-queue.

delica1 avatar delica1 commented on June 18, 2024

from persist-queue.

peter-wangxu avatar peter-wangxu commented on June 18, 2024

Did you use the file based queue or sqlite based queue?

On my first thought, storing the hash value in sqlite as a column is possible, we can check the uniqueness via SQL, but for filed based queue, no idea for now.

Do you have any idea?

from persist-queue.

delica1 avatar delica1 commented on June 18, 2024

from persist-queue.

delica1 avatar delica1 commented on June 18, 2024

from persist-queue.

peter-wangxu avatar peter-wangxu commented on June 18, 2024

That's a good news.

A set like queue can be useful in many cases. I do support adding this:

  • it can be a new queue, say it's SetQueue, we can optimize it on demand
  • either, doing as you mentioned.

Although, I prefer the first one, the second option is also welcome.
Do you mind sending out the PR for either solution?

Thanks
Peter

from persist-queue.

delica1 avatar delica1 commented on June 18, 2024

This works for me but can't fully test right now.

class UniqueQ(persistqueue.SQLiteQueue):
    _TABLE_NAME = 'unique_queue'
    _SQL_CREATE = ('CREATE TABLE IF NOT EXISTS {table_name} ('
                   '{key_column} INTEGER PRIMARY KEY AUTOINCREMENT, '
                   'data BLOB, timestamp FLOAT, UNIQUE (data))')

    def put(self, item):
      obj = pickle.dumps(item)
      try:
        self._insert_into(obj, _time.time())
      except sqlite3.IntegrityError:
        #print("UNIQUE constraint failed")
        pass
      else:
        self.total += 1
        self.put_event.set()

from persist-queue.

peter-wangxu avatar peter-wangxu commented on June 18, 2024

Looks fine for me, but need to add some test to cover this.

To create PR, please follow below steps:

  1. fork this project.
  2. clone your forked project to local.
  3. create a new branch, say unique_queue, then begin to make changes and commit.
  4. git push origin unique_queue.
  5. then your can create the PR based your branch by clicking the button New pull request on this page.

from persist-queue.

peter-wangxu avatar peter-wangxu commented on June 18, 2024

@delica1 Do you meet any obstacle for the patch:)

from persist-queue.

delica1 avatar delica1 commented on June 18, 2024

from persist-queue.

peter-wangxu avatar peter-wangxu commented on June 18, 2024

Fixed in PR: #41

from persist-queue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.