CANCELLED
please, do not consider this patch
On 07-04-2016 15:13, Paulo Ricardo Paz Vital wrote:
On Apr 07 02:38PM, Lucio Correia wrote:
> On 07-04-2016 14:28, Jose Ricardo Ziviani wrote:
>> - This commit implements two new methods for object store, update_data
>> and update_id. Now it's possible to update an existing data
>> instead of delete/create.
>>
>> Signed-off-by: Jose Ricardo Ziviani <joserz(a)linux.vnet.ibm.com>
>> ---
>> src/wok/objectstore.py | 13 +++++++++++++
>> tests/test_objectstore.py | 11 +++++++++++
>> 2 files changed, 24 insertions(+)
>>
>> diff --git a/src/wok/objectstore.py b/src/wok/objectstore.py
>> index ff3796c..5ec87eb 100644
>> --- a/src/wok/objectstore.py
>> +++ b/src/wok/objectstore.py
>> @@ -94,6 +94,19 @@ class ObjectStoreSession(object):
>> (ident, obj_type, jsonstr, version))
>> self.conn.commit()
>>
>> + def update_data(self, obj_type, ident, data):
>> + jsonstr = json.dumps(data)
>> + c = self.conn.cursor()
>> + c.execute('UPDATE objects SET json=? WHERE id=? AND type=?',
>> + (jsonstr, ident, obj_type))
>> + self.conn.commit()
> I see that store() could be used to update existent entries as well, because
> it first removes the entry and then adds it again with same id.
> Is there any difference here?
I was going to use update when editing templates, it was a semantic
issue but I changed the way I'm implementing template edit
>
In addition to Lucio's question, I'd like to know which case impacts more in
perfomance: update or remove/add (store again)?
Good point, I've been looking for benchmarks on the internet but didn't
find anything reliable.
One guy made some measurements
(
http://stackoverflow.com/a/29141391/54837), it took 30ms to update 500
rows against 62ms to delete/insert but there are more variables to consider.
Anyway, on our case I don't think it makes any difference due to the
amount of data we handle.
>
>> +
>> + def update_id(self, obj_type, ident, new_ident):
>> + c = self.conn.cursor()
>> + c.execute('UPDATE objects SET id=? WHERE id=? AND type=?',
>> + (new_ident, ident, obj_type))
>> + self.conn.commit()
>> +
>>
>> class ObjectStore(object):
>> def __init__(self, location=None):
>> diff --git a/tests/test_objectstore.py b/tests/test_objectstore.py
>> index 3ea7b70..d6ea434 100644
>> --- a/tests/test_objectstore.py
>> +++ b/tests/test_objectstore.py
>> @@ -82,6 +82,17 @@ class ObjectStoreTests(unittest.TestCase):
>> item = session.get_object_version('fǒǒ', 'těst1')
>> self.assertEquals(get_version().split('-')[0], item[0])
>>
>> + # test update data
>> + session.update_data('fǒǒ', 'těst1', {'α':
5})
>> + item = session.get('fǒǒ', 'těst1')
>> + self.assertEquals(5, item[u'α'])
>> +
>> + # test update id
>> + session.update_id('fǒǒ', 'těst1', 'těst2')
>> + item = session.get('fǒǒ', 'těst2')
>> + self.assertEquals(5, item[u'α'])
>> +
>> +
>> def test_object_store_threaded(self):
>> def worker(ident):
>> with store as session:
>>
>>
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel(a)ovirt.org
>>
http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>
>
> --
> Lucio Correia
> Software Engineer
> IBM LTC Brazil
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel(a)ovirt.org
>
http://lists.ovirt.org/mailman/listinfo/kimchi-devel
--
Jose Ricardo Ziviani
-----------------------------
Software Engineer
Linux Technology Center - IBM