parsav  Diff

Differences From Artifact [96ec125a09]:

To Artifact [dc07991d31]:


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