Skip to content

Commit

Permalink
just filter the rows actually
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBigBoss committed Jul 28, 2024
1 parent 19f65ef commit c5d4ee3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 139 deletions.
40 changes: 0 additions & 40 deletions .snaplet/snaplet-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,6 @@ type Override = {
request_id?: string;
};
}
job?: {
name?: string;
fields?: {
jobid?: string;
schedule?: string;
command?: string;
nodename?: string;
nodeport?: string;
database?: string;
username?: string;
active?: string;
jobname?: string;
};
}
job_run_details?: {
name?: string;
fields?: {
jobid?: string;
runid?: string;
job_pid?: string;
database?: string;
username?: string;
command?: string;
status?: string;
return_message?: string;
start_time?: string;
end_time?: string;
};
}
storage_migrations?: {
name?: string;
fields?: {
Expand Down Expand Up @@ -642,17 +613,6 @@ export interface Fingerprint {
createdAt?: FingerprintDateField;
requestId?: FingerprintNumberField;
}
jobs?: {
jobid?: FingerprintNumberField;
nodeport?: FingerprintNumberField;
}
jobRunDetails?: {
jobid?: FingerprintNumberField;
runid?: FingerprintNumberField;
jobPid?: FingerprintNumberField;
startTime?: FingerprintDateField;
endTime?: FingerprintDateField;
}
storageMigrations?: {
id?: FingerprintNumberField;
executedAt?: FingerprintDateField;
Expand Down
40 changes: 1 addition & 39 deletions .snaplet/snaplet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,39 +175,6 @@ interface Table_shovel_integrations {
name: string | null;
conf: Json | null;
}
interface Table_cron_job {
jobid: number;
schedule: string;
command: string;
nodename: string;
nodeport: number;
database: string;
username: string;
active: boolean;
/**
* We couldn't determine the type of this column. The type might be coming from an unknown extension
* or be specific to your database. Please if it's a common used type report this issue so we can fix it!
* Otherwise, please manually type this column by casting it to the correct type.
* @example
* Here is a cast example for copycat use:
* ```
* copycat.scramble(row.unknownColumn as string)
* ```
*/
jobname: unknown | null;
}
interface Table_cron_job_run_details {
jobid: number | null;
runid: number;
job_pid: number | null;
database: string | null;
username: string | null;
command: string | null;
status: string | null;
return_message: string | null;
start_time: string | null;
end_time: string | null;
}
interface Table_pgsodium_key {
id: string;
status: Enum_pgsodium_key_status | null;
Expand Down Expand Up @@ -623,10 +590,6 @@ interface Schema_auth {
sso_providers: Table_auth_sso_providers;
users: Table_auth_users;
}
interface Schema_cron {
job: Table_cron_job;
job_run_details: Table_cron_job_run_details;
}
interface Schema_dbdev {

}
Expand Down Expand Up @@ -710,7 +673,6 @@ interface Database {
_analytics: Schema__analytics;
_realtime: Schema__realtime;
auth: Schema_auth;
cron: Schema_cron;
dbdev: Schema_dbdev;
extensions: Schema_extensions;
graphql: Schema_graphql;
Expand All @@ -729,7 +691,7 @@ interface Database {
vault: Schema_vault;
}
interface Extension {
extensions: "http" | "pg_cron" | "pg_net" | "pg_stat_statements" | "pg_trgm" | "pgcrypto" | "pgjwt" | "uuid-ossp";
extensions: "http" | "pg_net" | "pg_stat_statements" | "pg_trgm" | "pgcrypto" | "pgjwt" | "uuid-ossp";
graphql: "pg_graphql";
pgsodium: "pgsodium";
pgtle: "pg_tle";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
set check_function_bodies = off;

-- create trigger function for filtering send_account_transfers with no send_account_created
create or replace function private.filter_send_account_transfers_with_no_send_account_created()
returns trigger
language plpgsql
security definer
as $$
begin
-- Deletes send_account_transfers with no send_account_created.
-- This is due to performance issues in our shovel indexer and using filter_ref to limit indexing to only
-- send_account_transfers with send_account_created.
-- For now, we index all USDC and SEND token transfers, and use this function cron job to delete the rest.
-- See https://github.com/orgs/indexsupply/discussions/268
if exists ( select 1 from send_account_created where account = new.f )
or exists ( select 1 from send_account_created where account = new.t )
then
return new;
else
return null;
end if;
end;
$$;

-- create trigger on send_account_transfers table
create trigger filter_send_account_transfers_with_no_send_account_created
before insert on public.send_account_transfers
for each row
execute function private.filter_send_account_transfers_with_no_send_account_created();

This file was deleted.

62 changes: 58 additions & 4 deletions supabase/tests/send_account_transfers_test.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BEGIN;
SELECT plan(3);
SELECT plan(5);

-- Create the necessary extensions
CREATE EXTENSION "basejump-supabase_test_helpers"; -- noqa: RF05
Expand All @@ -8,6 +8,10 @@ CREATE EXTENSION "basejump-supabase_test_helpers"; -- noqa: RF05
SELECT tests.create_supabase_user('test_user_from');
SELECT tests.create_supabase_user('test_user_to');

insert into send_account_created (chain_id, log_addr, block_time, user_op_hash, tx_hash, account, ig_name, src_name, block_num, tx_idx, log_idx)
values (8453, '\xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', floor(extract(EPOCH FROM timestamptz '2013-07-01 12:00:00')), '\x1234', '\x1234', '\x1234567890ABCDEF1234567890ABCDEF12345678', 'send_account_created', 'send_account_created', 1, 0, 0),
(8453, '\xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', floor(extract(EPOCH FROM timestamptz '2013-07-01 12:00:00')), '\x1234', '\x1234', '\xB0B7D5E8A4B6D534B3F608E9D27871F85A4E98DA', 'send_account_transfers', 'send_account_transfers', 1, 0, 0);

INSERT INTO send_accounts (user_id, address, chain_id, init_code)
VALUES (
tests.get_supabase_uid('test_user_from'),
Expand Down Expand Up @@ -57,7 +61,7 @@ VALUES (
-- Test if the trigger function populated the additional columns correctly
SELECT results_eq(
$$
select
select
(data->>'log_addr')::citext as log_addr,
(data->>'f')::citext as f,
(data->>'t')::citext as t,
Expand Down Expand Up @@ -102,8 +106,8 @@ WHERE id = (
-- Test if the delete was successful
SELECT is_empty(
$$
SELECT id
FROM send_account_transfers
SELECT id
FROM send_account_transfers
WHERE f = '\x1234567890ABCDEF1234567890ABCDEF12345678'::bytea AND t = '\xB0B7D5E8A4B6D534B3F608E9D27871F85A4E98DA'::bytea
$$,
'Test if the trigger function removes the activity row'
Expand All @@ -120,5 +124,55 @@ SELECT is_empty(
'Test if the trigger function removes the activity row'
);

-- Test filter_non_send_account_transfers_before_insert removes transactions when the sender is not a send account
delete from send_account_transfers;
INSERT INTO send_account_transfers (
f,
t,
v,
block_time,
ig_name,
src_name,
tx_hash,
block_num,
tx_idx,
log_idx,
abi_idx,
chain_id,
log_addr
)
VALUES (
'\xa71CE00000000000000000000000000000000000',
'\xb055000000000000000000000000000000000000',
100,
floor(extract(EPOCH FROM timestamptz '2013-07-01 12:00:00')),
'send_account_transfers',
'send_account_transfers',
'\x1234',
1,
0,
0,
0,
8453,
'\xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
);

SELECT is_empty(
$$
select 1
from send_account_transfers
where f = '\xa71CE00000000000000000000000000000000000'
$$,
'Test if the trigger function filters send_account_transfers with no send_account_created'
);

select is_empty(
$$
select 1
from send_account_transfers
$$,
'Test if the trigger function filters send_account_transfers with no send_account_created'
);

SELECT * FROM finish();
ROLLBACK;

0 comments on commit c5d4ee3

Please sign in to comment.