13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
...
696
697
698
699
700
701
702
703
704
705
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
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
....
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
....
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
....
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
....
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
|
params = {uint64}, sql = [[
select domain, key, knownsince, parsav from parsav_servers
where id = $1::bigint
]];
};
conf_get = {
params = {rawstring}, sql = [[
select value from parsav_config
where key = $1::text limit 1
]];
};
conf_set = {
params = {rawstring,rawstring}, cmd=true, sql = [[
insert into parsav_config (key, value)
values ($1::text, $2::text)
on conflict (key) do update set value = $2::text
]];
};
conf_reset = {
................................................................................
params = {uint64,uint64}, sql = [[
select name, id, owner, array_length(members,1) from parsav_circles where
($1::bigint = 0 or $1::bigint = owner) and
($2::bigint = 0 or $2::bigint = id)
]];
};
circle_members_fetch_cid = {
params = {uint64, uint64}, sql = [[
select unnest(members) from parsav_circles where
($1::bigint = 0 or owner = $1::bigint) and
id = $2::bigint
]];
};
circle_members_fetch_name = {
params = {uint64, pstring}, sql = [[
select unnest(members) from parsav_circles where
($1::bigint = 0 or owner = $1::bigint) and
name = $2::text
]];
................................................................................
order by c.tltime desc
limit case when $3::bigint = 0 then null
else $3::bigint end
offset $4::bigint
]];
};
timeline_actor_fetch = {
params = {uint64, uint64, uint64, uint64, uint64}, sql = [[
with followed as (
select relatee from parsav_rels where
kind = <rel:follow> and
relator = $1::bigint
), avoided as (
select relatee as avoidee from parsav_rels where
kind = <rel:avoid> or kind = <rel:mute> and
relator = $1::bigint
union select relator as avoidee from parsav_rels where
kind = <rel:exclude> and
relatee = $1::bigint
)
................................................................................
select (c.post).*
from pg_temp.parsavpg_known_content as c
where ($2::bigint = 0 or c.tltime <= $2::bigint) and
($3::bigint = 0 or $3::bigint < c.tltime) and
(c.promoter in (table followed) or
c.promoter = $1::bigint) and
not ((c.post).author in (table avoided))
order by c.tltime desc
limit case when $4::bigint = 0 then null
else $4::bigint end
offset $5::bigint
]];
};
................................................................................
artifacts = array_remove(artifacts, $2::bigint)
where id = $1::bigint and
artifacts @> array[$2::bigint]
]];
};
actor_conf_str_get = {
params = {uint64, rawstring}, sql = [[
select value from parsav_actor_conf_strs where
uid = $1::bigint and
key = $2::text
limit 1
]];
};
actor_conf_str_set = {
params = {uint64, rawstring, rawstring}, cmd = true, sql = [[
insert into parsav_actor_conf_strs (uid,key,value)
values ($1::bigint, $2::text, $3::text)
on conflict (uid,key) do update set value = $3::text
]];
};
actor_conf_str_enum = {
params = {uint64}, sql = [[
select value from parsav_actor_conf_strs where uid = $1::bigint
]];
};
actor_conf_str_reset = {
params = {uint64, rawstring}, cmd = true, sql = [[
delete from parsav_actor_conf_strs where
uid = $1::bigint and ($2::text is null or key = $2::text)
]]
};
actor_conf_int_get = {
params = {uint64, rawstring}, sql = [[
select value from parsav_actor_conf_ints where
uid = $1::bigint and
key = $2::text
limit 1
]];
};
actor_conf_int_set = {
params = {uint64, rawstring, uint64}, cmd = true, sql = [[
insert into parsav_actor_conf_ints (uid,key,value)
values ($1::bigint, $2::text, $3::bigint)
on conflict (uid,key) do update set value = $3::bigint
]];
};
actor_conf_int_enum = {
params = {uint64}, sql = [[
select value from parsav_actor_conf_ints where uid = $1::bigint
]];
};
actor_conf_int_reset = {
params = {uint64, rawstring}, cmd = true, sql = [[
delete from parsav_actor_conf_ints where
uid = $1::bigint and ($2::text is null or key = $2::text)
]]
};
}
local struct pqr {
................................................................................
return true
else
lib.warn('backend pgsql - failed to obliterate database: \n', lib.pq.PQresultErrorMessage(res))
return false
end
end];
conf_get = [terra(src: &lib.store.source, key: rawstring)
var r = queries.conf_get.exec(src, key)
if r.sz == 0 then return [lib.mem.ptr(int8)] { ptr = nil, ct = 0 } else
defer r:free()
return r:String(0,0)
end
end];
conf_set = [terra(src: &lib.store.source, key: rawstring, val: rawstring)
queries.conf_set.exec(src, key, val):free() end];
conf_reset = [terra(src: &lib.store.source, key: rawstring)
queries.conf_reset.exec(src, key):free() end];
actor_fetch_uid = [terra(src: &lib.store.source, uid: uint64)
var r = queries.actor_fetch_uid.exec(src, uid)
if r.sz == 0 then
................................................................................
timeline_instance_fetch = [terra(
src: &lib.store.source,
rg: lib.store.range
): lib.mem.lstptr(lib.store.post)
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) -- MUST FREE ALL
ret.ptr[i].ptr.source = src
end
................................................................................
auth_sigtime_user_alter = [terra(
src: &lib.store.source,
uid: uint64,
time: lib.store.timepoint
): {} queries.auth_sigtime_user_alter.exec(src, uid, time) end];
actor_conf_str_enum = nil;
actor_conf_str_get = [terra(src: &lib.store.source, uid: uint64, key: rawstring): pstring
var r = queries.actor_conf_str_get.exec(src, uid, key)
if r.sz > 0 then
var ret = r:String(0,0)
r:free()
return ret
else return pstring.null() end
end];
actor_conf_str_set = [terra(src: &lib.store.source, uid: uint64, key: rawstring, value: rawstring): {}
queries.actor_conf_str_set.exec(src,uid,key,value) end];
actor_conf_str_reset = [terra(src: &lib.store.source, uid: uint64, key: rawstring): {}
queries.actor_conf_str_reset.exec(src,uid,key) end];
actor_conf_int_enum = nil;
actor_conf_int_get = [terra(src: &lib.store.source, uid: uint64, key: rawstring)
var r = queries.actor_conf_int_get.exec(src, uid, key)
if r.sz > 0 then
var ret = r:int(uint64,0,0)
r:free()
return ret, true
end
return 0, false
end];
actor_conf_int_set = [terra(src: &lib.store.source, uid: uint64, key: rawstring, value: uint64): {}
queries.actor_conf_int_set.exec(src,uid,key,value) end];
actor_conf_int_reset = [terra(src: &lib.store.source, uid: uint64, key: rawstring): {}
queries.actor_conf_int_reset.exec(src,uid,key) end];
circle_search = [terra(
src: &lib.store.source,
pool:&lib.mem.pool,
uid: uint64,
cid: uint64
................................................................................
if res.sz == 0 then return [lib.mem.ptr(lib.store.circle)].null() end
defer res:free()
var rt = pool:alloc(lib.store.circle, res.sz)
for i = 0, res.sz do
var name = res:_string(i,0)
rt(i) = lib.store.circle {
name = name:pdup(pool);
cid = res:int(uint64,i,1);
owner = res:int(uint64,i,2);
memcount = res:int(uint64,i,3);
}
end
return rt
end];
circle_members_fetch_cid = [terra(
src: &lib.store.source,
pool:&lib.mem.pool,
uid: uint64,
cid: uint64
): lib.mem.ptr(uint64)
var res = queries.circle_members_fetch_cid.exec(src,uid,cid)
if res.sz == 0 then return [lib.mem.ptr(uint64)].null() end
defer res:free()
var rt = pool:alloc(uint64, res.sz)
for i = 0, res.sz do rt(i) = res:int(uint64,i,0) end
return rt
end];
actor_auth_register_uid = nil; -- TODO better support non-view based auth
}
return b
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
<
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
<
<
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
<
|
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
...
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
...
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
...
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
....
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
....
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
....
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
....
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
|
params = {uint64}, sql = [[
select domain, key, knownsince, parsav from parsav_servers
where id = $1::bigint
]];
};
conf_get = {
params = {pstring}, sql = [[
select value from parsav_config
where key = $1::text limit 1
]];
};
conf_set = {
params = {pstring,pstring}, cmd=true, sql = [[
insert into parsav_config (key, value)
values ($1::text, $2::text)
on conflict (key) do update set value = $2::text
]];
};
conf_reset = {
................................................................................
params = {uint64,uint64}, sql = [[
select name, id, owner, array_length(members,1) from parsav_circles where
($1::bigint = 0 or $1::bigint = owner) and
($2::bigint = 0 or $2::bigint = id)
]];
};
circle_create = {
params = {uint64,pstring}, sql = [[
insert into parsav_circles (owner,name)
values ($1::bigint, $2::text)
returning id
]];
};
circle_destroy = {
params = {uint64,uint64}, cmd = true, sql = [[
delete from parsav_circles where
owner = $1::bigint and
id = $2::bigint
]];
};
circle_memberships_uid = {
params = {uint64, uint64}, sql = [[
select name, id, owner, array_length(members,1) from parsav_circles where
owner = $1::bigint and
members @> array[$2::bigint]
]];
};
circle_members_fetch_cid = {
params = {uint64}, sql = [[
select unnest(members) from parsav_circles where
id = $1::bigint
]];
};
circle_members_fetch_name = {
params = {uint64, pstring}, sql = [[
select unnest(members) from parsav_circles where
($1::bigint = 0 or owner = $1::bigint) and
name = $2::text
]];
................................................................................
order by c.tltime desc
limit case when $3::bigint = 0 then null
else $3::bigint end
offset $4::bigint
]];
};
timeline_circle_fetch = {
params = {uint64, uint64, uint64, uint64, uint64}, sql = [[
with circle as (
select unnest(members) from parsav_circles where id = $1::bigint
)
select (c.post).*
from pg_temp.parsavpg_known_content as c
where ($2::bigint = 0 or c.tltime <= $2::bigint) and
($3::bigint = 0 or $3::bigint < c.tltime) and
(c.promoter in (table circle) or
c.promoter = (select owner from parsav_circles where id = $1::bigint))
order by c.tltime desc
limit case when $4::bigint = 0 then null
else $4::bigint end
offset $5::bigint
]];
};
timeline_actor_fetch = {
params = {uint64, uint64, uint64, uint64, uint64}, sql = [[
with followed as (
select relatee from parsav_rels where
kind = <rel:follow> and
relator = $1::bigint
), avoided as ( -- not strictly necessary but lets us minimize how much data needs to be sent back to parsav for filtering
select relatee as avoidee from parsav_rels where
kind = <rel:avoid> or kind = <rel:mute> and
relator = $1::bigint
union select relator as avoidee from parsav_rels where
kind = <rel:exclude> and
relatee = $1::bigint
)
................................................................................
select (c.post).*
from pg_temp.parsavpg_known_content as c
where ($2::bigint = 0 or c.tltime <= $2::bigint) and
($3::bigint = 0 or $3::bigint < c.tltime) and
(c.promoter in (table followed) or
c.promoter = $1::bigint) and
not ((c.post).author in (table avoided)) and
not (c.promoter in (table avoided))
order by c.tltime desc
limit case when $4::bigint = 0 then null
else $4::bigint end
offset $5::bigint
]];
};
................................................................................
artifacts = array_remove(artifacts, $2::bigint)
where id = $1::bigint and
artifacts @> array[$2::bigint]
]];
};
actor_conf_str_get = {
params = {uint64, pstring}, sql = [[
select value from parsav_actor_conf_strs where
uid = $1::bigint and
key = $2::text
limit 1
]];
};
actor_conf_str_set = {
params = {uint64, pstring, pstring}, cmd = true, sql = [[
insert into parsav_actor_conf_strs (uid,key,value)
values ($1::bigint, $2::text, $3::text)
on conflict (uid,key) do update set value = $3::text
]];
};
actor_conf_str_enum = {
params = {uint64}, sql = [[
select value from parsav_actor_conf_strs where uid = $1::bigint
]];
};
actor_conf_str_reset = {
params = {uint64, pstring}, cmd = true, sql = [[
delete from parsav_actor_conf_strs where
uid = $1::bigint and ($2::text is null or key = $2::text)
]]
};
actor_conf_int_get = {
params = {uint64, pstring}, sql = [[
select value from parsav_actor_conf_ints where
uid = $1::bigint and
key = $2::text
limit 1
]];
};
actor_conf_int_set = {
params = {uint64, pstring, uint64}, cmd = true, sql = [[
insert into parsav_actor_conf_ints (uid,key,value)
values ($1::bigint, $2::text, $3::bigint)
on conflict (uid,key) do update set value = $3::bigint
]];
};
actor_conf_int_enum = {
params = {uint64}, sql = [[
select value from parsav_actor_conf_ints where uid = $1::bigint
]];
};
actor_conf_int_reset = {
params = {uint64, pstring}, cmd = true, sql = [[
delete from parsav_actor_conf_ints where
uid = $1::bigint and ($2::text is null or key = $2::text)
]]
};
}
local struct pqr {
................................................................................
return true
else
lib.warn('backend pgsql - failed to obliterate database: \n', lib.pq.PQresultErrorMessage(res))
return false
end
end];
conf_get = [terra(src: &lib.store.source, key: pstring)
var r = queries.conf_get.exec(src, key)
if r.sz == 0 then return [lib.mem.ptr(int8)] { ptr = nil, ct = 0 } else
defer r:free()
return r:String(0,0)
end
end];
conf_set = [terra(src: &lib.store.source, key: pstring, val: pstring)
queries.conf_set.exec(src, key, val):free() end];
conf_reset = [terra(src: &lib.store.source, key: rawstring)
queries.conf_reset.exec(src, key):free() end];
actor_fetch_uid = [terra(src: &lib.store.source, uid: uint64)
var r = queries.actor_fetch_uid.exec(src, uid)
if r.sz == 0 then
................................................................................
timeline_instance_fetch = [terra(
src: &lib.store.source,
rg: lib.store.range
): lib.mem.lstptr(lib.store.post)
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) -- MUST FREE ALL
ret.ptr[i].ptr.source = src
end
return ret
end];
timeline_circle_fetch = [terra(
src: &lib.store.source,
cid: uint64,
rg: lib.store.range
): lib.mem.lstptr(lib.store.post)
var r = pqr { sz = 0 }
var A,B,C,D = rg:matrix() -- :/
r = queries.timeline_circle_fetch.exec(src,cid,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) -- MUST FREE ALL
ret.ptr[i].ptr.source = src
end
................................................................................
auth_sigtime_user_alter = [terra(
src: &lib.store.source,
uid: uint64,
time: lib.store.timepoint
): {} queries.auth_sigtime_user_alter.exec(src, uid, time) end];
actor_conf_str_enum = nil;
actor_conf_str_get = [terra(
src: &lib.store.source,
pool: &lib.mem.pool,
uid: uint64,
key: pstring
): pstring
var r = queries.actor_conf_str_get.exec(src, uid, key)
if r.sz > 0 then
return r:_string(0,0):pdup(pool)
else return pstring.null() end
end];
actor_conf_str_set = [terra(src: &lib.store.source, uid: uint64, key: pstring, value: pstring): {}
queries.actor_conf_str_set.exec(src,uid,key,value) end];
actor_conf_str_reset = [terra(src: &lib.store.source, uid: uint64, key: pstring): {}
queries.actor_conf_str_reset.exec(src,uid,key) end];
actor_conf_int_enum = nil;
actor_conf_int_get = [terra(src: &lib.store.source, uid: uint64, key: pstring)
var r = queries.actor_conf_int_get.exec(src, uid, key)
if r.sz > 0 then
var ret = r:int(uint64,0,0)
r:free()
return ret, true
end
return 0, false
end];
actor_conf_int_set = [terra(src: &lib.store.source, uid: uint64, key: pstring, value: uint64): {}
queries.actor_conf_int_set.exec(src,uid,key,value) end];
actor_conf_int_reset = [terra(src: &lib.store.source, uid: uint64, key: pstring): {}
queries.actor_conf_int_reset.exec(src,uid,key) end];
circle_search = [terra(
src: &lib.store.source,
pool:&lib.mem.pool,
uid: uint64,
cid: uint64
................................................................................
if res.sz == 0 then return [lib.mem.ptr(lib.store.circle)].null() end
defer res:free()
var rt = pool:alloc(lib.store.circle, res.sz)
for i = 0, res.sz do
var name = res:_string(i,0)
rt(i) = lib.store.circle {
name = name:pdup(pool); cid = res:int(uint64,i,1);
owner = res:int(uint64,i,2); memcount = res:int(uint64,i,3);
}
end
return rt
end];
circle_create = [terra(
src: &lib.store.source,
owner: uint64,
name: pstring
): uint64
var r = queries.circle_create.exec(src, owner, name)
if r.sz > 0 then defer r:free() return r:int(uint64,0,0) end
return 0
end];
circle_destroy = [terra(
src: &lib.store.source,
owner: uint64,
cid: uint64
): {} queries.circle_destroy.exec(src, owner, cid) end];
circle_memberships_uid = [terra(
src: &lib.store.source,
pool:&lib.mem.pool,
owner: uint64,
subject: uint64
): lib.mem.ptr(lib.store.circle)
var res = queries.circle_memberships_uid.exec(src, owner, subject)
if res.sz == 0 then return [lib.mem.ptr(lib.store.circle)].null() end
defer res:free()
var rt = pool:alloc(lib.store.circle, res.sz)
for i = 0, res.sz do
var name = res:_string(i,0)
rt(i) = lib.store.circle {
name = name:pdup(pool); cid = res:int(uint64,i,1);
owner = res:int(uint64,i,2); memcount = res:int(uint64,i,3);
}
end
return rt
end];
circle_members_fetch_cid = [terra(
src: &lib.store.source,
pool:&lib.mem.pool,
cid: uint64
): lib.mem.ptr(uint64)
var res = queries.circle_members_fetch_cid.exec(src,cid)
if res.sz == 0 then return [lib.mem.ptr(uint64)].null() end
defer res:free()
var rt = pool:alloc(uint64, res.sz)
for i = 0, res.sz do rt(i) = res:int(uint64,i,0) end
return rt
end];
actor_auth_register_uid = nil; -- TODO better support non-view based auth
}
return b
|