Backstory
I work on the backend for Android clients. There are a lot of data to be displayed and some offline functionality needed, so I have to solve synchronization. Said data consists of temp-tables.
Our solution
Right now, to let the client know about possible changes and not to enforce complete client db wipe and creation (takes a lot of time), I make a hash of each of the temp-table rows. Said hash is created by taking the temp-table row, creating a JSON for it and then making a hash out of that JSON. It is working.
My problems with this solution
I think it is not the ideal solution. All those operations look demanding and from my testing, it shows:
- For each for some data; the base line, no action = 90 ms
- Population a temp-table inside of that for each with buffer-copy = 400 ms
- Calculating hash with the above solution after the population inside the for each = 2 880 ms
What I want
I am interested if we are doing something wrong. Is there a better solution for this problem? Is there less demanding way for creating hash out of each individual temp-table record?
We are currently using OpenEdge 10.2B.
Procedure responsible for hash creation, create_hash create widget-pool.
define input parameter inp_hBuffer as handle no-undo.
define output parameter out_cHash as c no-undo.
define var ttDynamic as handle no-undo.
define var hBufferTT as handle no-undo.
define var lResult as l no-undo.
define var cDataTT as longchar no-undo.
define var itime as i.
do on error undo,return error:
if not(valid-handle(inp_hBuffer) and inp_hBuffer:type = 'BUFFER':u) then
return error substitute('Neplatny typ vstupniho parametru predaneho procedure "&1".','m_ghashb':u).
create temp-table ttDynamic.
ttDynamic:add-fields-from(inp_hBuffer).
ttDynamic:temp-table-prepare(inp_hBuffer:table).
hBufferTT = ttDynamic:default-buffer-handle.
hBufferTT:buffer-copy(inp_hBuffer).
ttDynamic:write-json('longchar':u,cDataTT).
out_cHash = hex-encode(md5-digest(cDataTT)).
end.
return.
And its usage
for first lbUsrtab where
lbUsrtab.ucje = GetUcje('m_usrtab':U) and
lbUsrtab.login-name = LoginName no-lock,
each lbWcesta where
lbWcesta.ucje = GetUcje('wcesta':U) and
lbWcesta.kodu = lbUsrtab.kodu no-lock,
each lbWciorg where
lbWciorg.ucje = GetUcje('wciorg':U) and
lbWciorg.cest = lbWcesta.cest no-lock,
each lbKontaktr where
lbKontaktr.ucje = GetUcje('kontaktr':U) and
lbKontaktr.corg = lbWciorg.corg no-lock
by lbKontaktr.zako descending
on error undo, return error return-value:
create ttKontaktr.
buffer-copy lbKontaktr to ttKontaktr.
run create_hash(input buffer ttKontaktr:handle, output ttKontaktr.hash).
end.
What I want
- to know if we are doing something wrong, this solution does not look right to me for some reason and I feel confident that someone had to face this too (creating a hash of a temp-table)
- it does take a lot of time and should be a problem in the future, so I would like to approach this sooner rather than later