Differences From
Artifact [962a3e64e0]:
213 213 select a.id, a.nym, a.handle, a.origin, a.bio,
214 214 a.avataruri, a.rank, a.quota, a.key, a.epithet,
215 215 extract(epoch from a.knownsince)::bigint,
216 216 coalesce(a.handle || '@' || s.domain,
217 217 '@' || a.handle) as xid,
218 218
219 219 au.restrict,
220 - array['post' ] <@ au.restrict as can_post,
221 - array['edit' ] <@ au.restrict as can_edit,
222 - array['acct' ] <@ au.restrict as can_acct,
223 - array['upload'] <@ au.restrict as can_upload,
224 - array['censor'] <@ au.restrict as can_censor,
225 - array['admin' ] <@ au.restrict as can_admin
220 + array['post' ] <@ au.restrict,
221 + array['edit' ] <@ au.restrict,
222 + array['account' ] <@ au.restrict,
223 + array['upload' ] <@ au.restrict,
224 + array['moderate'] <@ au.restrict,
225 + array['admin' ] <@ au.restrict
226 226
227 227 from parsav_auth au
228 228 left join parsav_actors a on au.uid = a.id
229 229 left join parsav_servers s on a.origin = s.id
230 230
231 231 where au.aid = $1::bigint and au.blacklist = false and
232 232 (au.netmask is null or au.netmask >> $2::inet) and
................................................................................
349 349 params = {uint64}, cmd = true, sql = [[
350 350 delete from parsav_posts where id = $1::bigint
351 351 ]]
352 352 };
353 353
354 354 post_fetch = {
355 355 params = {uint64}, sql = [[
356 + with counts as (
357 + select a.kind, p.id as subject, count(*) as ct from parsav_acts as a
358 + inner join parsav_posts as p on p.id = a.subject
359 + group by a.kind, p.id
360 + )
361 +
356 362 select a.origin is null,
357 363 p.id, p.author, p.subject, p.acl, p.body,
358 364 extract(epoch from p.posted )::bigint,
359 365 extract(epoch from p.discovered)::bigint,
360 366 extract(epoch from p.edited )::bigint,
361 367 p.parent, p.convoheaduri, p.chgcount,
362 - coalesce(c.value, -1)::smallint
368 + coalesce(c.value, -1)::smallint, 0::bigint, 0::bigint,
369 + coalesce((select ct from counts where kind = 'like' and counts.subject = p.id),0)::integer,
370 + coalesce((select ct from counts where kind = 'rt' and counts.subject = p.id),0)::integer
363 371
364 372 from parsav_posts as p
365 373 inner join parsav_actors as a on p.author = a.id
366 374 left join parsav_actor_conf_ints as c on c.uid = a.id and c.key = 'ui-accent'
367 375 where p.id = $1::bigint
368 376 ]];
369 377 };
370 378
371 379 post_enum_parent = {
372 380 params = {uint64}, sql = [[
381 + with counts as (
382 + select a.kind, p.id as subject, count(*) as ct from parsav_acts as a
383 + inner join parsav_posts as p on p.id = a.subject
384 + group by a.kind, p.id
385 + )
386 +
373 387 select a.origin is null,
374 388 p.id, p.author, p.subject, p.acl, p.body,
375 389 extract(epoch from p.posted )::bigint,
376 390 extract(epoch from p.discovered)::bigint,
377 391 extract(epoch from p.edited )::bigint,
378 392 p.parent, p.convoheaduri, p.chgcount,
379 - coalesce(c.value, -1)::smallint
393 + coalesce(c.value, -1)::smallint, 0::bigint, 0::bigint,
394 + coalesce((select ct from counts where kind = 'like' and counts.subject = p.id),0)::integer,
395 + coalesce((select ct from counts where kind = 'rt' and counts.subject = p.id),0)::integer
380 396
381 397 from parsav_posts as p
382 398 inner join parsav_actors as a on a.id = p.author
383 399 left join parsav_actor_conf_ints as c on c.uid = a.id and c.key = 'ui-accent'
384 400 where p.parent = $1::bigint
385 401 order by p.posted, p.discovered asc
386 402 ]]
................................................................................
401 417 inner join parsav_posts as p
402 418 on p.id = posts.id
403 419 )
404 420
405 421 select extract(epoch from max(m))::bigint from maxes
406 422 ]];
407 423 };
424 +
425 + post_react_simple = {
426 + params = {uint64, uint64, pstring}, sql = [[
427 + insert into parsav_acts (kind,actor,subject) values (
428 + $3::text, $1::bigint, $2::bigint
429 + ) returning id
430 + ]];
431 + };
432 +
433 + post_react_cancel = {
434 + params = {uint64, uint64, pstring}, cmd = true, sql = [[
435 + delete from parsav_acts where
436 + actor = $1::bigint and
437 + subject = $2::bigint and
438 + kind = $3::text
439 + ]];
440 + };
441 +
442 + post_reacts_fetch_uid = {
443 + params = {uint64, uint64, pstring}, sql = [[
444 + select id, actor, subject, kind, body, time from parsav_acts where
445 + ($1::bigint = 0 or actor = $1::bigint) and
446 + ($2::bigint = 0 or subject = $2::bigint) and
447 + ($3::text is null or kind = $3::text )
448 + ]]
449 + };
408 450
409 451 post_enum_author_uid = {
410 452 params = {uint64,uint64,uint64,uint64, uint64}, sql = [[
453 + with ownposts as (
454 + select *, 0::bigint as rtid from parsav_posts as p
455 + where p.author = $5::bigint and
456 + ($1::bigint = 0 or p.posted <= to_timestamp($1::bigint)) and
457 + ($2::bigint = 0 or to_timestamp($2::bigint) < p.posted)
458 + ),
459 +
460 + retweets as (
461 + select p.*, a.id as rtid from parsav_acts as a
462 + inner join parsav_posts as p on a.subject = p.id
463 + where a.actor = $5::bigint and
464 + a.kind = 'rt' and
465 + ($1::bigint = 0 or a.time <= to_timestamp($1::bigint)) and
466 + ($2::bigint = 0 or to_timestamp($2::bigint) < a.time)
467 + ),
468 +
469 + allposts as (select *, 0::bigint as retweeter from ownposts
470 + union select *, $5::bigint as retweeter from retweets),
471 +
472 + counts as (
473 + select a.kind, p.id as subject, count(*) as ct from parsav_acts as a
474 + inner join parsav_posts as p on p.id = a.subject
475 + group by a.kind, p.id
476 + )
477 +
411 478 select a.origin is null,
412 479 p.id, p.author, p.subject, p.acl, p.body,
413 480 extract(epoch from p.posted )::bigint,
414 481 extract(epoch from p.discovered)::bigint,
415 482 extract(epoch from p.edited )::bigint,
416 483 p.parent, p.convoheaduri, p.chgcount,
417 - coalesce((select value from parsav_actor_conf_ints as c where
418 - c.uid = $1::bigint and c.key = 'ui-accent'),-1)::smallint
419 -
420 - from parsav_posts as p
484 + coalesce(c.value,-1)::smallint,
485 + p.retweeter, p.rtid,
486 + coalesce((select ct from counts where kind = 'like' and counts.subject = p.id),0)::integer,
487 + coalesce((select ct from counts where kind = 'rt' and counts.subject = p.id),0)::integer
488 + from allposts as p
421 489 inner join parsav_actors as a on p.author = a.id
422 - where p.author = $5::bigint and
423 - ($1::bigint = 0 or p.posted <= to_timestamp($1::bigint)) and
424 - ($2::bigint = 0 or to_timestamp($2::bigint) < p.posted)
490 + left join parsav_actor_conf_ints as c
491 + on c.key = 'ui-accent' and
492 + c.uid = a.id
425 493 order by (p.posted, p.discovered) desc
426 494 limit case when $3::bigint = 0 then null
427 - else $3::bigint end
495 + else $3::bigint end
428 496 offset $4::bigint
429 497 ]]
430 498 };
431 499
432 500 -- maybe there's some way to unify these two, idk, im tired
433 501
434 502 timeline_instance_fetch = {
435 503 params = {uint64, uint64, uint64, uint64}, sql = [[
436 - select true,
437 - p.id, p.author, p.subject, p.acl, p.body,
438 - extract(epoch from p.posted )::bigint,
439 - extract(epoch from p.discovered)::bigint,
440 - extract(epoch from p.edited )::bigint,
441 - p.parent, null::text, p.chgcount,
442 - coalesce(c.value, -1)::smallint
443 -
444 - from parsav_posts as p
445 - inner join parsav_actors as a on p.author = a.id
446 - left join parsav_actor_conf_ints as c on c.uid = a.id and c.key = 'ui-accent'
447 - where
448 - ($1::bigint = 0 or p.posted <= to_timestamp($1::bigint)) and
449 - ($2::bigint = 0 or to_timestamp($2::bigint) < p.posted) and
450 - (a.origin is null)
451 - order by (p.posted, p.discovered) desc
452 - limit case when $3::bigint = 0 then null
453 - else $3::bigint end
454 - offset $4::bigint
504 + with posts as (
505 + select true,
506 + p.id, p.author, p.subject, p.acl, p.body,
507 + extract(epoch from p.posted )::bigint,
508 + extract(epoch from p.discovered)::bigint,
509 + extract(epoch from p.edited )::bigint,
510 + p.parent, null::text, p.chgcount,
511 + coalesce(c.value, -1)::smallint, 0::bigint, 0::bigint
512 +
513 + from parsav_posts as p
514 + inner join parsav_actors as a on p.author = a.id
515 + left join parsav_actor_conf_ints as c on c.uid = a.id and c.key = 'ui-accent'
516 + where
517 + ($1::bigint = 0 or p.posted <= to_timestamp($1::bigint)) and
518 + ($2::bigint = 0 or to_timestamp($2::bigint) < p.posted) and
519 + (a.origin is null)
520 + order by (p.posted, p.discovered) desc
521 + limit case when $3::bigint = 0 then null
522 + else $3::bigint end
523 + offset $4::bigint
524 + ), counts as (
525 + select a.kind, p.id as subject, count(*) as ct from parsav_acts as a
526 + inner join parsav_posts as p on p.id = a.subject
527 + group by a.kind, p.id
528 + )
529 +
530 + select *,
531 + coalesce((select ct from counts as c where kind = 'like' and c.subject = posts.id),0)::integer,
532 + coalesce((select ct from counts as c where kind = 'rt' and c.subject = posts.id),0)::integer
533 + from posts
455 534 ]]
456 535 };
457 536
458 537 artifact_instantiate = {
459 538 params = {binblob, binblob, pstring}, sql = [[
460 539 insert into parsav_artifacts (content,hash,mime) values (
461 540 $1::bytea, $2::bytea, $3::text
................................................................................
792 871 end
793 872 p.ptr.parent = r:int(uint64,row,9)
794 873 if r:null(row,11)
795 874 then p.ptr.chgcount = 0
796 875 else p.ptr.chgcount = r:int(uint32,row,11)
797 876 end
798 877 p.ptr.accent = r:int(int16,row,12)
878 + p.ptr.rtdby = r:int(uint64,row,13)
879 + p.ptr.rtact = r:int(uint64,row,14)
880 + p.ptr.likes = r:int(uint32,row,15)
881 + p.ptr.rts = r:int(uint32,row,16)
799 882 p.ptr.localpost = r:bool(row,0)
800 883
801 884 return p
802 885 end
803 886 local terra row_to_actor(r: &pqr, row: intptr): lib.mem.ptr(lib.store.actor)
804 887 var a: lib.mem.ptr(lib.store.actor)
805 888 var av: rawstring, avlen: intptr
................................................................................
1161 1244 a.ptr.source = src
1162 1245
1163 1246 var au = [lib.stat(lib.store.auth)] { ok = true }
1164 1247 au.val.aid = aid
1165 1248 au.val.uid = a.ptr.id
1166 1249 if not r:null(0,14) then -- restricted?
1167 1250 au.val.privs:clear()
1168 - (au.val.privs.post << r:bool(0,15))
1169 - (au.val.privs.edit << r:bool(0,16))
1170 - (au.val.privs.acct << r:bool(0,17))
1171 - (au.val.privs.upload << r:bool(0,18))
1172 - (au.val.privs.censor << r:bool(0,19))
1173 - (au.val.privs.admin << r:bool(0,20))
1251 + (au.val.privs.post << r:bool(0,15))
1252 + (au.val.privs.edit << r:bool(0,16))
1253 + (au.val.privs.account << r:bool(0,17))
1254 + (au.val.privs.upload << r:bool(0,18))
1255 + (au.val.privs.moderate<< r:bool(0,19))
1256 + (au.val.privs.admin << r:bool(0,20))
1174 1257 else au.val.privs:fill() end
1175 1258
1176 1259 return au, a
1177 1260 end
1178 1261
1179 1262 ::fail:: return [lib.stat (lib.store.auth) ] { ok = false },
1180 1263 [lib.mem.ptr(lib.store.actor)] { ptr = nil, ct = 0 }
................................................................................
1211 1294 ): lib.mem.ptr(lib.store.post)
1212 1295 var r = queries.post_fetch.exec(src, post)
1213 1296 if r.sz == 0 then return [lib.mem.ptr(lib.store.post)].null() end
1214 1297 var p = row_to_post(&r, 0)
1215 1298 p.ptr.source = src
1216 1299 return p
1217 1300 end];
1301 +
1302 + post_retweet = [terra(
1303 + src: &lib.store.source,
1304 + uid: uint64,
1305 + post: uint64,
1306 + undo: bool
1307 + ): {}
1308 + if not undo then
1309 + queries.post_react_simple.exec(src,uid,post,"rt")
1310 + else
1311 + queries.post_react_cancel.exec(src,uid,post,"rt")
1312 + end
1313 + end];
1314 + post_like = [terra(
1315 + src: &lib.store.source,
1316 + uid: uint64,
1317 + post: uint64,
1318 + undo: bool
1319 + ): {}
1320 + if not undo then
1321 + queries.post_react_simple.exec(src,uid,post,"like")
1322 + else
1323 + queries.post_react_cancel.exec(src,uid,post,"like")
1324 + end
1325 + end];
1326 + post_liked_uid = [terra(
1327 + src: &lib.store.source,
1328 + uid: uint64,
1329 + post: uint64
1330 + ): bool
1331 + var q = queries.post_reacts_fetch_uid.exec(src,uid,post,'like')
1332 + if q.sz > 0 then q:free() return true end
1333 + return false
1334 + end];
1218 1335
1219 1336 timeline_instance_fetch = [terra(src: &lib.store.source, rg: lib.store.range)
1220 1337 var r = pqr { sz = 0 }
1221 1338 var A,B,C,D = rg:matrix() -- :/
1222 1339 r = queries.timeline_instance_fetch.exec(src,A,B,C,D)
1223 1340
1224 1341 var ret: lib.mem.ptr(lib.mem.ptr(lib.store.post)) ret:init(r.sz)