update with sort in c code

This commit is contained in:
Joseph 2023-02-06 08:57:55 -05:00
parent 6d3efbe900
commit c0e6ce7519
No known key found for this signature in database
GPG Key ID: E709789D3076B5CC
5 changed files with 154 additions and 42 deletions

View File

@ -301,6 +301,7 @@ noinst_PROGRAMS = \
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH; AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
TESTS = \ TESTS = \
$(check_PROGRAMS) $(check_PROGRAMS)
test_exchangedb_postgres_SOURCES = \ test_exchangedb_postgres_SOURCES = \
test_exchangedb.c test_exchangedb.c
test_exchangedb_postgres_LDADD = \ test_exchangedb_postgres_LDADD = \
@ -375,5 +376,6 @@ perf_deposits_get_ready_postgres_LDADD = \
-lm \ -lm \
$(XLIB) $(XLIB)
EXTRA_test_exchangedb_postgres_DEPENDENCIES = \ EXTRA_test_exchangedb_postgres_DEPENDENCIES = \
libtaler_plugin_exchangedb_postgres.la libtaler_plugin_exchangedb_postgres.la

View File

@ -13,11 +13,7 @@
-- You should have received a copy of the GNU General Public License along with -- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-- --
/*DROP FUNCTION exchange_do_refund_by_coin(
IN in_coin_pub BYTEA,
IN in_merchant_pub BYTEA,
IN in_h_contract BYTEA
);*/
CREATE OR REPLACE FUNCTION exchange_do_get_link_data( CREATE OR REPLACE FUNCTION exchange_do_get_link_data(
IN in_coin_pub BYTEA IN in_coin_pub BYTEA
) )
@ -53,7 +49,11 @@ LOOP
ON (tp.melt_serial_id=rrc.melt_serial_id) ON (tp.melt_serial_id=rrc.melt_serial_id)
JOIN denominations denoms JOIN denominations denoms
ON (rrc.denominations_serial=denoms.denominations_serial) ON (rrc.denominations_serial=denoms.denominations_serial)
WHERE rrc.melt_serial_id =i.melt_serial_id; WHERE rrc.melt_serial_id =i.melt_serial_id
/* GROUP BY tp.transfer_pub, denoms.denom_pub, rrc.ev_sig,rrc.ewv,rrc.link_sig,rrc.freshcoin_index, rrc.coin_ev*/
ORDER BY tp.transfer_pub,
rrc.freshcoin_index ASC
;
END LOOP; END LOOP;
CLOSE curs; CLOSE curs;
END $$; END $$;

View File

@ -28,37 +28,42 @@ DECLARE
var_coin_pub BYTEA; var_coin_pub BYTEA;
DECLARE DECLARE
var_deposit_serial_id INT8; var_deposit_serial_id INT8;
BEGIN DECLARE
curs CURSOR
SELECT FOR
SELECT
coin_pub coin_pub
,deposit_serial_id ,deposit_serial_id
INTO ,wire_deadline
var_coin_pub ,shard
,var_deposit_serial_id
FROM deposits_by_ready FROM deposits_by_ready
WHERE wire_deadline <= in_now WHERE wire_deadline <= in_now
AND shard >= in_start_shard_now AND shard >=in_start_shard_now
AND shard <=in_end_shard_now AND shard <=in_end_shard_now
ORDER BY LIMIT 1;
wire_deadline ASC DECLARE
,shard ASC; i RECORD;
BEGIN
SELECT OPEN curs;
merchant_pub FETCH FROM curs INTO i;
,wire_target_h_payto IF NOT FOUND
INTO THEN
out_merchant_pub RETURN;
,var_wire_target_h_payto END IF;
FROM deposits
WHERE coin_pub=var_coin_pub
AND deposit_serial_id=var_deposit_serial_id;
SELECT SELECT
payto_uri payto_uri
INTO out_payto_uri ,merchant_pub
FROM wire_targets INTO
WHERE wire_target_h_payto=var_wire_target_h_payto; out_payto_uri
,out_merchant_pub
FROM deposits dep
JOIN wire_targets wt
ON (wt.wire_target_h_payto=dep.wire_target_h_payto)
WHERE dep.coin_pub=i.coin_pub
AND dep.deposit_serial_id=i.deposit_serial_id
ORDER BY
i.wire_deadline ASC
,i.shard ASC;
RETURN; RETURN;
END $$; END $$;

View File

@ -58,7 +58,10 @@ struct LinkDataContext
enum GNUNET_GenericReturnValue status; enum GNUNET_GenericReturnValue status;
}; };
struct Results {
struct TALER_EXCHANGEDB_LinkList *pos;
struct TALER_TransferPublicKeyP transfer_pub;
};
/** /**
* Free memory of the link data list. * Free memory of the link data list.
* *
@ -82,6 +85,16 @@ free_link_data_list (void *cls,
} }
} }
static int
transfer_pub_cmp (const void *a,
const void *b)
{
const struct Results *ra = a;
const struct Results *rb = b;
return GNUNET_memcmp (&ra->transfer_pub,
&rb->transfer_pub);
}
/** /**
* Function to be called with the results of a SELECT statement * Function to be called with the results of a SELECT statement
@ -97,6 +110,10 @@ add_ldl (void *cls,
unsigned int num_results) unsigned int num_results)
{ {
struct LinkDataContext *ldctx = cls; struct LinkDataContext *ldctx = cls;
struct Results *temp= GNUNET_new_array (num_results,
struct Results);;
unsigned int temp_off = 0;
for (int i = num_results - 1; i >= 0; i--) for (int i = num_results - 1; i >= 0; i--)
{ {
@ -141,6 +158,45 @@ add_ldl (void *cls,
} }
TALER_blinded_planchet_free (&bp); TALER_blinded_planchet_free (&bp);
} }
temp[temp_off].pos = pos;
temp[temp_off].transfer_pub = transfer_pub;
temp_off++;
}
qsort (temp,
temp_off,
sizeof (struct Results),
transfer_pub_cmp);
for (unsigned int i = 0; i < temp_off; i++)
{
struct TALER_EXCHANGEDB_LinkList *pos;
struct Results *r = &temp[i];
pos = GNUNET_new (struct TALER_EXCHANGEDB_LinkList);
pos->orig_coin_link_sig = r->pos->orig_coin_link_sig;
pos->ev_sig = r->pos->ev_sig;
pos->coin_refresh_offset = r->pos->coin_refresh_offset;
pos->alg_values = r->pos->alg_values;
pos->denom_pub = r->pos->denom_pub;
pos->nonce = r->pos->nonce;
pos->have_nonce = r->pos->have_nonce;
pos->next = ldctx->last;
ldctx->last = pos;
}
if (NULL != ldctx->last)
{
ldctx->ldc (ldctx->ldc_cls,
&ldctx->transfer_pub,
ldctx->last);
free_link_data_list (ldctx,
ldctx->last);
}
ldctx->last = NULL;
GNUNET_free(temp);
/*
if ( (NULL != ldctx->last) && if ( (NULL != ldctx->last) &&
(0 == GNUNET_memcmp (&transfer_pub, (0 == GNUNET_memcmp (&transfer_pub,
&ldctx->transfer_pub)) ) &ldctx->transfer_pub)) )
@ -161,6 +217,7 @@ add_ldl (void *cls,
} }
ldctx->last = pos; ldctx->last = pos;
} }
GNUNET_free(temp);*/
} }
@ -267,6 +324,54 @@ TEH_PG_get_link_data (void *cls,
" ,freshcoin_index INT4" " ,freshcoin_index INT4"
" ,coin_ev BYTEA);"); " ,coin_ev BYTEA);");
break; break;
case 3:
query="get_link_v3";
PREPARE (pg,
query,
"SELECT "
" tp.transfer_pub"
",denoms.denom_pub"
",rrc.ev_sig"
",rrc.ewv"
",rrc.link_sig"
",rrc.freshcoin_index"
",rrc.coin_ev"
" FROM refresh_commitments"
" JOIN refresh_revealed_coins rrc"
" USING (melt_serial_id)"
" JOIN refresh_transfer_keys tp"
" USING (melt_serial_id)"
" JOIN denominations denoms"
" ON (rrc.denominations_serial = denoms.denominations_serial)"
" WHERE old_coin_pub=$1");
break;
case 4:
query="get_link_v4";
PREPARE (pg,
query,
"WITH rc AS MATERIALIZED ("
"SELECT"
" melt_serial_id"
" FROM refresh_commitments"
" WHERE old_coin_pub=$1"
")"
"SELECT "
" tp.transfer_pub"
",denoms.denom_pub"
",rrc.ev_sig"
",rrc.ewv"
",rrc.link_sig"
",rrc.freshcoin_index"
",rrc.coin_ev "
"FROM "
"refresh_revealed_coins rrc"
" JOIN refresh_transfer_keys tp"
" USING (melt_serial_id)"
" JOIN denominations denoms"
" USING (denominations_serial)"
" WHERE rrc.melt_serial_id = (SELECT melt_serial_id FROM rc)"
);
break;
default: default:
GNUNET_break (0); GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;