1. codernity
  2. CodernityDB
  3. Issues
Issue #6 invalid

When I delete an entity, did I need to `reindex`?

dreampuf
created an issue

Here use case

@app.route("/admin", methods=["GET", "POST"])
def admin():
    if "admin" not in session:
        return redirect(url_for("login"))

    items = sorted([i["doc"] for i in g.db.all("item", -1, with_doc=True, with_storage=True)],
                   key=itemgetter("item"))

    if request.method == "POST":
        for i in items:
            g.db.delete(i)

        for i in request.form.get("items", "").strip().splitlines():
            item = i.strip()
            g.db.insert({"item": time.time(), "d": item})

        g.db.reindex() # if i don't execute this, i will get the `raise RecordDeleted("Deleted")` exception.
        return redirect(url_for("admin"))

    return render_template("admin.html", items=items)

Comments (5)

  1. codernity repo owner

    Hey,

    No, reindex operation may be needed only:

    • when you add index when there are data in db
    • when you change existing index (make_key_value especially)

    So there is no need to reindex after delete / update.

    here is a demo that I think covers your case:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    
    from CodernityDB.database import Database
    
    import shutil
    
    s = """
    name: test
    type: HashIndex
    key_format: I
    make_key_value:
    t, None
    """
    
    p = '/tmp/test_5'
    
    try:
        shutil.rmtree(p)
    except:
        pass
    
    
    db = Database(p)
    
    db.create()
    
    db.add_index(s)
    
    for x in xrange(10):
        db.insert(dict(t=x))
    
    for curr in db.all("test", -1, with_doc=True, with_storage=True):
        db.delete(curr['doc'])
    
    for x in xrange(10, 20):
        db.insert(dict(t=x))
    
    for curr in db.all('test', -1, with_doc=True, with_storage=True):
        print curr
    

    Can you please provide more details ? Where does it raise that exception (full traceback) ? Please keep in mind that this is also covered in tests so it shouldn't at all.

  2. codernity repo owner

    Please change from invalid if you will be able to show failing case. Because we can't reproduce the problem, and no feedback was done, we're invalidating this issue now.

  3. Log in to comment