205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
...
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
|
$1::bigint, case when $2::text = '' then null else $2::text end,
$3::text, $4::text,
now(), now(), array[]::bigint[], array[]::bigint[]
) returning id
]]; -- TODO array handling
};
instance_timeline_fetch = {
params = {uint64, uint64, uint64, uint64}, sql = [[
select true,
p.id, p.author, p.subject, p.acl, p.body,
extract(epoch from p.posted )::bigint,
extract(epoch from p.discovered)::bigint,
p.parent, null::text
from parsav_posts as p
................................................................................
else
return pqr {ct, res}
end
end
end
local terra row_to_post(r: &pqr, row: intptr): lib.mem.ptr(lib.store.post)
--lib.io.fmt("body ptr %p len %llu\n", r:string(row,5), r:len(row,5))
--lib.io.fmt("acl ptr %p len %llu\n", r:string(row,4), r:len(row,4))
var subj: rawstring, sblen: intptr
if r:null(row,3)
then subj = nil sblen = 0
else subj = r:string(row,3) sblen = r:len(row,3)+1
end
var p = [ lib.str.encapsulate(lib.store.post, {
subject = { `subj, `sblen };
acl = {`r:string(row,4), `r:len(row,4)+1};
body = {`r:string(row,5), `r:len(row,5)+1};
--convoheaduri = { `nil, `0 }; --FIXME
}) ]
p.ptr.id = r:int(uint64,row,1)
p.ptr.author = r:int(uint64,row,2)
p.ptr.posted = r:int(uint64,row,6)
p.ptr.discovered = r:int(uint64,row,7)
if r:null(row,8)
then p.ptr.parent = 0
................................................................................
var r = queries.post_create.exec(src,post.author,post.subject,post.acl,post.body)
if r.sz == 0 then return 0 end
defer r:free()
var id = r:int(uint64,0,0)
return id
end];
instance_timeline_fetch = [terra(src: &lib.store.source, rg: lib.store.range)
var r = pqr { sz = 0 }
if rg.mode == 0 then
r = queries.instance_timeline_fetch.exec(src,rg.from_time,rg.to_time,0,0)
elseif rg.mode == 1 then
r = queries.instance_timeline_fetch.exec(src,rg.from_time,0,rg.to_idx,0)
elseif rg.mode == 2 then
r = queries.instance_timeline_fetch.exec(src,0,rg.to_time,0,rg.from_idx)
elseif rg.mode == 3 then
r = queries.instance_timeline_fetch.exec(src,0,0,rg.to_idx,rg.from_idx)
end
var ret: lib.mem.ptr(lib.mem.ptr(lib.store.post)) ret:init(r.sz)
for i=0,r.sz do ret.ptr[i] = row_to_post(&r, i) end -- MUST FREE ALL
return ret
end];
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
<
>
>
>
>
>
|
|
|
|
<
>
|
|
<
>
|
<
|
>
>
>
>
>
>
>
>
>
|
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
...
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
$1::bigint, case when $2::text = '' then null else $2::text end,
$3::text, $4::text,
now(), now(), array[]::bigint[], array[]::bigint[]
) returning id
]]; -- TODO array handling
};
post_enum_author_uid = {
params = {uint64,uint64,uint64,uint64, uint64}, sql = [[
select a.origin is null,
p.id, p.author, p.subject, p.acl, p.body,
extract(epoch from p.posted )::bigint,
extract(epoch from p.discovered)::bigint,
p.parent, p.convoheaduri
from parsav_posts as p
inner join parsav_actors as a on p.author = a.id
where p.author = $5::bigint and
($1::bigint = 0 or p.posted <= to_timestamp($1::bigint)) and
($2::bigint = 0 or to_timestamp($2::bigint) < p.posted)
order by (p.posted, p.discovered) desc
limit case when $3::bigint = 0 then null
else $3::bigint end
offset $4::bigint
]]
};
-- maybe there's some way to unify these two, idk, im tired
timeline_instance_fetch = {
params = {uint64, uint64, uint64, uint64}, sql = [[
select true,
p.id, p.author, p.subject, p.acl, p.body,
extract(epoch from p.posted )::bigint,
extract(epoch from p.discovered)::bigint,
p.parent, null::text
from parsav_posts as p
................................................................................
else
return pqr {ct, res}
end
end
end
local terra row_to_post(r: &pqr, row: intptr): lib.mem.ptr(lib.store.post)
var subj: rawstring, sblen: intptr
var cvhu: rawstring, cvhlen: intptr
if r:null(row,3)
then subj = nil sblen = 0
else subj = r:string(row,3) sblen = r:len(row,3)+1
end
if r:null(row,9)
then cvhu = nil cvhlen = 0
else cvhu = r:string(row,9) cvhlen = r:len(row,9)+1
end
var p = [ lib.str.encapsulate(lib.store.post, {
subject = { `subj, `sblen };
acl = {`r:string(row,4), `r:len(row,4)+1};
body = {`r:string(row,5), `r:len(row,5)+1};
convoheaduri = { `cvhu, `cvhlen }; --FIXME
}) ]
p.ptr.id = r:int(uint64,row,1)
p.ptr.author = r:int(uint64,row,2)
p.ptr.posted = r:int(uint64,row,6)
p.ptr.discovered = r:int(uint64,row,7)
if r:null(row,8)
then p.ptr.parent = 0
................................................................................
var r = queries.post_create.exec(src,post.author,post.subject,post.acl,post.body)
if r.sz == 0 then return 0 end
defer r:free()
var id = r:int(uint64,0,0)
return id
end];
timeline_instance_fetch = [terra(src: &lib.store.source, rg: lib.store.range)
var r = pqr { sz = 0 }
var A,B,C,D = rg:matrix() -- :/
r = queries.timeline_instance_fetch.exec(src,A,B,C,D)
var ret: lib.mem.ptr(lib.mem.ptr(lib.store.post)) ret:init(r.sz)
for i=0,r.sz do ret.ptr[i] = row_to_post(&r, i) end -- MUST FREE ALL
return ret
end];
post_enum_author_uid = [terra(
src: &lib.store.source,
uid: uint64,
rg: lib.store.range
): lib.mem.ptr(lib.mem.ptr(lib.store.post))
var r = pqr { sz = 0 }
var A,B,C,D = rg:matrix() -- :/
r = queries.post_enum_author_uid.exec(src,A,B,C,D,uid)
var ret: lib.mem.ptr(lib.mem.ptr(lib.store.post)) ret:init(r.sz)
for i=0,r.sz do ret.ptr[i] = row_to_post(&r, i) end -- MUST FREE ALL
return ret
end];
|