parsav  Diff

Differences From Artifact [80ca2205e4]:

To Artifact [5d4cebec04]:


   477    477   			limit case when $4::bigint = 0 then null
   478    478   					   else $4::bigint end
   479    479   			offset $5::bigint
   480    480   		]];
   481    481   	};
   482    482   
   483    483   	artifact_instantiate = {
   484         -		params = {binblob, binblob, pstring}, sql = [[
   485         -			insert into parsav_artifacts (content,hash,mime) values (
   486         -				$1::bytea, $2::bytea, $3::text
          484  +		params = {binblob, binblob, pstring, int64}, sql = [[
          485  +			insert into parsav_artifacts (content,hash,mime,birth) values (
          486  +				$1::bytea, $2::bytea, $3::text,$4::bigint
   487    487   			) on conflict do nothing returning id
   488    488   		]];
   489    489   	};
   490    490   	artifact_expropriate = {
   491         -		params = {uint64, uint64, pstring}, cmd = true, sql = [[
   492         -			insert into parsav_artifact_claims (uid,rid,description,folder) values (
   493         -				$1::bigint, $2::bigint, $3::text, 'new'
          491  +		params = {uint64, uint64, pstring, pstring, int64}, cmd = true, sql = [[
          492  +			insert into parsav_artifact_claims (uid,rid,description,folder,birth) values (
          493  +				$1::bigint, $2::bigint, $3::text, $4::text, $5::bigint
   494    494   			) on conflict do nothing
   495    495   		]];
   496    496   	};
   497    497   	artifact_quicksearch = {
   498    498   		params = {binblob}, sql = [[
   499    499   			select id, (content is null) from parsav_artifacts where hash = $1::bytea
   500    500   				limit 1
................................................................................
   529    529   	-- "ERROR:  cannot insert multiple commands into a prepared
   530    530   	--  statement" are you fucking shitting me with this shit
   531    531   		params = {uint64}, sql = [[
   532    532   			delete from parsav_artifact_claims where
   533    533   				rid = $1::bigint
   534    534   			returning uid, description, birth, folder;
   535    535   		]];
          536  +	};
          537  +	artifact_enum_uid = {
          538  +		params = {uint64, pstring}, sql = [[
          539  +			select (pg_temp.parsavpg_translate_artifact(a)).*
          540  +			from parsav_artifact_claims as a where uid = $1::bigint and
          541  +				($2::text is null or
          542  +				 ($2::text = '' and folder is null) or
          543  +				 $2::text = folder)
          544  +			order by birth desc
          545  +		]];
          546  +	};
          547  +	artifact_fetch = {
          548  +		params = {uint64, uint64}, sql = [[
          549  +			select (pg_temp.parsavpg_translate_artifact(a)).*
          550  +			from parsav_artifact_claims as a where uid = $1::bigint and rid = $2::bigint
          551  +		]];
          552  +	};
          553  +	artifact_load = {
          554  +		params = {uint64}, sql = [[
          555  +			select content, mime from parsav_artifacts where id = $1::bigint
          556  +		]];
   536    557   	};
   537    558   	post_attach_ctl_ins = {
   538    559   		params = {uint64, uint64}, cmd=true, sql = [[
   539    560   			update parsav_posts set
   540    561   				artifacts = artifacts || $2::bigint
   541    562   			where id = $1::bigint and not
   542    563   				artifacts @> array[$2::bigint] -- prevent duplication
................................................................................
  1530   1551   			if ban then
  1531   1552   				lib.report('user attempted to instantiate forsaken artifact')
  1532   1553   				return 0
  1533   1554   			end
  1534   1555   			var oldid = srec:int(uint64,0,0)
  1535   1556   			return oldid
  1536   1557   		else -- not in db, insert
  1537         -			var nrec = queries.artifact_instantiate.exec(src, artifact, hashb, mime)
         1558  +			var nrec = queries.artifact_instantiate.exec(src, artifact, hashb, mime, lib.osclock.time(nil))
  1538   1559   			if nrec.sz == 0 then
  1539   1560   				lib.warn('failed to instantiate artifact -- are you running out of storage?')
  1540   1561   				return 0
  1541   1562   			else defer nrec:free()
  1542   1563   				var newid = nrec:int(uint64,0,0)
  1543   1564   				return newid
  1544   1565   			end
  1545   1566   		end
  1546   1567   	end];
         1568  +
         1569  +	artifact_expropriate = [terra(
         1570  +		src: &lib.store.source,
         1571  +		uid: uint64,
         1572  +		artifact: uint64,
         1573  +		desc: pstring,
         1574  +		folder: pstring
         1575  +	): {}
         1576  +		queries.artifact_expropriate.exec(src,uid,artifact,desc,folder, lib.osclock.time(nil))
         1577  +	end];
         1578  +
         1579  +	artifact_enum_uid = [terra(
         1580  +		src: &lib.store.source,
         1581  +		uid: uint64,
         1582  +		folder: pstring
         1583  +	)
         1584  +		var res = queries.artifact_enum_uid.exec(src,uid,folder)
         1585  +		if res.sz > 0 then
         1586  +			var m = lib.mem.heapa([lib.mem.ptr(lib.store.artifact)], res.sz)
         1587  +			for i=0,res.sz do
         1588  +				var id = res:int(uint64,i,0)
         1589  +				var idbuf: int8[lib.math.shorthand.maxlen]
         1590  +				var idlen = lib.math.shorthand.gen(id, &idbuf[0])
         1591  +				var desc = res:_string(i,2)
         1592  +				var folder = res:_string(i,3)
         1593  +				var mime = res:_string(i,4)
         1594  +				var url = lib.str.acc{}:init(48):lpush('/media/a/'):push(&idbuf[0],idlen):finalize() defer url:free()
         1595  +				m.ptr[i] = [ lib.str.encapsulate(lib.store.artifact, {
         1596  +					desc =  {`desc.ptr, `desc.ct + 1};
         1597  +					folder = {`folder.ptr, `folder.ct + 1};
         1598  +					mime = {`mime.ptr, `mime.ct + 1};
         1599  +					url = {`url.ptr, `url.ct + 1};
         1600  +				}) ]
         1601  +				m(i).ptr.rid = id
         1602  +				m(i).ptr.owner = uid
         1603  +			end
         1604  +			return m
         1605  +		else return [lib.mem.lstptr(lib.store.artifact)].null() end
         1606  +	end];
  1547   1607   
  1548   1608   	post_attach_ctl = [terra(
  1549   1609   		src: &lib.store.source,
  1550   1610   		post: uint64,
  1551   1611   		artifact: uint64,
  1552   1612   		detach: bool
  1553   1613   	): {}