parsav  Diff

Differences From Artifact [36b1398523]:

To Artifact [2c2a215381]:


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