Emmanuel BENOîT
74b6f2ab09
* Added various views and helper functions used by the mining computation but which may be re-used in other parts. * Added mining computation update type and associated update function * New constants: game.resources.weightBase (the value used to compute weights from mining settings) and game.resources.extraction (the quantity extracted in a day from a full provider at difficulty 0)
43 lines
No EOL
834 B
PL/PgSQL
43 lines
No EOL
834 B
PL/PgSQL
/*
|
|
* Utility functions used by unit tests
|
|
*
|
|
* Row lock checks
|
|
*/
|
|
|
|
CREATE TYPE _locks_entry AS (
|
|
ctid tid ,
|
|
shared BOOLEAN ,
|
|
exclusive BOOLEAN
|
|
);
|
|
|
|
CREATE OR REPLACE FUNCTION _get_locks_on(
|
|
IN _table TEXT )
|
|
RETURNS SETOF _locks_entry
|
|
STRICT VOLATILE
|
|
AS $$
|
|
|
|
DECLARE
|
|
_page INT;
|
|
_pages INT;
|
|
_record RECORD;
|
|
_return _locks_entry;
|
|
|
|
BEGIN
|
|
SELECT INTO _pages pg_relation_size( _table ) / 8192;
|
|
|
|
FOR _page IN 0 .. ( _pages - 1 )
|
|
LOOP
|
|
|
|
FOR _record IN SELECT t_ctid , t_infomask
|
|
FROM heap_page_items( get_raw_page( _table , _page ) )
|
|
WHERE t_xmax::text::int > ( txid_current( ) & x'ffffffff'::bigint )
|
|
LOOP
|
|
_return := ROW( _record.t_ctid ,
|
|
_record.t_infomask & x'80'::int <> 0 ,
|
|
_record.t_infomask & x'40'::int <> 0 );
|
|
RETURN NEXT _return;
|
|
END LOOP;
|
|
|
|
END LOOP;
|
|
END;
|
|
$$ LANGUAGE PLPGSQL; |