Skip to content

Commit

Permalink
drop is_politics column
Browse files Browse the repository at this point in the history
  • Loading branch information
sipec committed Jul 30, 2024
1 parent 50821fd commit 852dd49
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 120 deletions.
11 changes: 2 additions & 9 deletions backend/api/src/get-user-contract-metrics-with-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ const bodySchema = z
userId: z.string(),
limit: z.number(),
offset: z.number().gte(0).optional(),
isPolitics: z.boolean().optional(),
})
.strict()

export const getusercontractmetricswithcontracts = MaybeAuthedEndpoint(
async (req, auth) => {
const {
userId,
limit,
offset = 0,
isPolitics,
} = validate(bodySchema, req.body)
const { userId, limit, offset = 0 } = validate(bodySchema, req.body)
const visibilitySQL = getContractPrivacyWhereSQLFilter(
auth?.uid,
undefined,
Expand All @@ -41,12 +35,11 @@ export const getusercontractmetricswithcontracts = MaybeAuthedEndpoint(
and ucm.user_id='${userId}'
and ucm.data->'lastBetTime' is not null
and ucm.answer_id is null
and ($3 is null or c.is_politics = $3)
order by ((ucm.data)->'lastBetTime')::bigint desc offset $1
limit $2`
await pg.map(
q,
[offset, limit, isPolitics],
[offset, limit],
(data: {
contract_id: string
metrics: ContractMetric
Expand Down
2 changes: 0 additions & 2 deletions backend/api/src/supabase-search-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const search = async (
topicSlug: possibleTopicSlug,
forYou,
creatorId,
isPolitics,
marketTier,
} = props

Expand Down Expand Up @@ -116,7 +115,6 @@ const search = async (
uid: userId,
isForYou,
searchType,
isPolitics,
isPrizeMarket,
marketTier: marketTier as TierParamsType,
})
Expand Down
66 changes: 66 additions & 0 deletions backend/scripts/drop-is-politics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
create
or replace function public.contract_populate_cols () returns trigger language plpgsql as $function$
begin
if new.data is not null then
new.slug := (new.data) ->> 'slug';
new.question := (new.data) ->> 'question';
new.creator_id := (new.data) ->> 'creatorId';
new.visibility := (new.data) ->> 'visibility';
new.mechanism := (new.data) ->> 'mechanism';
new.outcome_type := (new.data) ->> 'outcomeType';
new.unique_bettor_count := ((new.data) -> 'uniqueBettorCount')::bigint;
new.tier := (new.data) ->> 'marketTier';
new.created_time := case
when new.data ? 'createdTime' then millis_to_ts(((new.data) ->> 'createdTime')::bigint)
else null
end;
new.close_time := case
when new.data ? 'closeTime' then millis_to_ts(((new.data) ->> 'closeTime')::bigint)
else null
end;
new.resolution_time := case
when new.data ? 'resolutionTime' then millis_to_ts(((new.data) ->> 'resolutionTime')::bigint)
else null
end;
new.resolution_probability := ((new.data) ->> 'resolutionProbability')::numeric;
new.resolution := (new.data) ->> 'resolution';
new.is_spice_payout := coalesce(((new.data) ->> 'isSpicePayout')::boolean, false);
new.popularity_score := coalesce(((new.data) ->> 'popularityScore')::numeric, 0);
new.deleted := coalesce(((new.data) ->> 'deleted')::boolean, false);
new.group_slugs := case
when new.data ? 'groupSlugs' then jsonb_array_to_text_array((new.data) -> 'groupSlugs')
else null
end;
new.last_updated_time := case
when new.data ? 'lastUpdatedTime' then millis_to_ts(((new.data) ->> 'lastUpdatedTime')::bigint)
else null
end;
new.last_bet_time := case
when new.data ? 'lastBetTime' then millis_to_ts(((new.data) ->> 'lastBetTime')::bigint)
else null
end;
new.last_comment_time := case
when new.data ? 'lastCommentTime' then millis_to_ts(((new.data) ->> 'lastCommentTime')::bigint)
else null
end;
end if;
return new;
end
$function$;

create
or replace function public.get_open_limit_bets_with_contracts_1 (uid text, count integer, politics boolean) returns table (contract_id text, bets jsonb[], contract jsonb) language sql stable parallel SAFE as $function$;
-- TODO: drop this function
select * from get_open_limit_bets_with_contracts(uid, count);
$function$;

alter table contracts
drop column if exists is_politics;

replace view public_contracts as
select
*
from
contracts
where
visibility = 'public';
6 changes: 2 additions & 4 deletions backend/shared/src/supabase/contract_comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@ export async function getCommentsDirect(
contractId?: string
limit?: number
page?: number
isPolitics?: boolean
}
) {
const { userId, contractId, limit = 5000, page = 0, isPolitics } = filters
const { userId, contractId, limit = 5000, page = 0 } = filters
return await pg.map(
`
select cc.data, likes from contract_comments cc
join contracts on cc.contract_id = contracts.id
where contracts.visibility = 'public'
and ($3 is null or contract_id = $3)
and ($4 is null or user_id = $4)
and ($5 is null or contracts.is_politics = $5)
order by cc.created_time desc
limit $1
offset $2
`,
[limit, page * limit, contractId, userId, isPolitics],
[limit, page * limit, contractId, userId],
(r) => convertContractComment(r)
)
}
3 changes: 0 additions & 3 deletions backend/shared/src/supabase/search-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export function getSearchContractSQL(args: {
uid?: string
isForYou?: boolean
searchType: SearchTypes
isPolitics?: boolean
isPrizeMarket?: boolean
marketTier: TierParamsType
}) {
Expand All @@ -189,7 +188,6 @@ export function getSearchContractSQL(args: {
groupId,
creatorId,
searchType,
isPolitics,
marketTier,

Check warning on line 191 in backend/shared/src/supabase/search-contracts.ts

View workflow job for this annotation

GitHub Actions / test

'marketTier' is assigned a value but never used. Allowed unused vars must match /^_/u
} = args
const hideStonks = sort === 'score' && !term.length && !groupId
Expand Down Expand Up @@ -227,7 +225,6 @@ export function getSearchContractSQL(args: {
),

whereSql,
isPolitics && where('is_politics = true'),
term.length && [
searchType === 'prefix' &&
where(
Expand Down
91 changes: 44 additions & 47 deletions backend/supabase/contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ create table if not exists
last_updated_time timestamp with time zone,
last_bet_time timestamp with time zone,
last_comment_time timestamp with time zone,
is_politics boolean default false,
freshness_score numeric default 0,
conversion_score numeric default 0 not null,
view_count bigint default 0,
Expand All @@ -51,52 +50,50 @@ execute function contract_populate_cols ();
create
or replace function public.contract_populate_cols () returns trigger language plpgsql as $function$
begin
if new.data is not null then
new.slug := (new.data) ->> 'slug';
new.question := (new.data) ->> 'question';
new.creator_id := (new.data) ->> 'creatorId';
new.visibility := (new.data) ->> 'visibility';
new.mechanism := (new.data) ->> 'mechanism';
new.outcome_type := (new.data) ->> 'outcomeType';
new.unique_bettor_count := ((new.data) -> 'uniqueBettorCount')::bigint;
new.tier := (new.data) ->> 'marketTier';
new.created_time := case
when new.data ? 'createdTime' then millis_to_ts(((new.data) ->> 'createdTime')::bigint)
else null
end;
new.close_time := case
when new.data ? 'closeTime' then millis_to_ts(((new.data) ->> 'closeTime')::bigint)
else null
end;
new.resolution_time := case
when new.data ? 'resolutionTime'
then millis_to_ts(((new.data) ->> 'resolutionTime')::bigint)
else null
end;
new.resolution_probability := ((new.data) ->> 'resolutionProbability')::numeric;
new.resolution := (new.data) ->> 'resolution';
new.is_spice_payout := coalesce(((new.data) ->> 'isSpicePayout')::boolean, false);
new.popularity_score := coalesce(((new.data) ->> 'popularityScore')::numeric, 0);
new.deleted := coalesce(((new.data) ->> 'deleted')::boolean, false);
new.group_slugs := case
when new.data ? 'groupSlugs' then jsonb_array_to_text_array((new.data) -> 'groupSlugs')
else null
end;
new.last_updated_time := case
when new.data ? 'lastUpdatedTime' then millis_to_ts(((new.data) ->> 'lastUpdatedTime')::bigint)
else null
end;
new.last_bet_time := case
when new.data ? 'lastBetTime' then millis_to_ts(((new.data) ->> 'lastBetTime')::bigint)
else null
end;
new.last_comment_time := case
when new.data ? 'lastCommentTime' then millis_to_ts(((new.data) ->> 'lastCommentTime')::bigint)
else null
end;
new.is_politics := coalesce(((new.data) ->> 'isPolitics')::boolean, false);
end if;
return new;
if new.data is not null then
new.slug := (new.data) ->> 'slug';
new.question := (new.data) ->> 'question';
new.creator_id := (new.data) ->> 'creatorId';
new.visibility := (new.data) ->> 'visibility';
new.mechanism := (new.data) ->> 'mechanism';
new.outcome_type := (new.data) ->> 'outcomeType';
new.unique_bettor_count := ((new.data) -> 'uniqueBettorCount')::bigint;
new.tier := (new.data) ->> 'marketTier';
new.created_time := case
when new.data ? 'createdTime' then millis_to_ts(((new.data) ->> 'createdTime')::bigint)
else null
end;
new.close_time := case
when new.data ? 'closeTime' then millis_to_ts(((new.data) ->> 'closeTime')::bigint)
else null
end;
new.resolution_time := case
when new.data ? 'resolutionTime' then millis_to_ts(((new.data) ->> 'resolutionTime')::bigint)
else null
end;
new.resolution_probability := ((new.data) ->> 'resolutionProbability')::numeric;
new.resolution := (new.data) ->> 'resolution';
new.is_spice_payout := coalesce(((new.data) ->> 'isSpicePayout')::boolean, false);
new.popularity_score := coalesce(((new.data) ->> 'popularityScore')::numeric, 0);
new.deleted := coalesce(((new.data) ->> 'deleted')::boolean, false);
new.group_slugs := case
when new.data ? 'groupSlugs' then jsonb_array_to_text_array((new.data) -> 'groupSlugs')
else null
end;
new.last_updated_time := case
when new.data ? 'lastUpdatedTime' then millis_to_ts(((new.data) ->> 'lastUpdatedTime')::bigint)
else null
end;
new.last_bet_time := case
when new.data ? 'lastBetTime' then millis_to_ts(((new.data) ->> 'lastBetTime')::bigint)
else null
end;
new.last_comment_time := case
when new.data ? 'lastCommentTime' then millis_to_ts(((new.data) ->> 'lastCommentTime')::bigint)
else null
end;
end if;
return new;
end
$function$;

Expand Down
21 changes: 3 additions & 18 deletions backend/supabase/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -502,24 +502,9 @@ limit count $function$;

create
or replace function public.get_open_limit_bets_with_contracts_1 (uid text, count integer, politics boolean) returns table (contract_id text, bets jsonb[], contract jsonb) language sql stable parallel SAFE as $function$;
select contract_id,
bets.data as bets,
contracts.data as contracts
from (
select contract_id,
array_agg(
data
order by created_time desc
) as data
from contract_bets
where user_id = uid
and (data->>'isFilled')::boolean = false
and (data->>'isCancelled')::boolean = false
group by contract_id
) as bets
join contracts on contracts.id = bets.contract_id
where (politics is false or is_politics = politics)
limit count $function$;
-- TODO: drop this function
select * from get_open_limit_bets_with_contracts(uid, count);
$function$;

create
or replace function public.get_option_voters (this_contract_id text, this_option_id text) returns table (data json) language sql parallel SAFE as $function$
Expand Down
4 changes: 2 additions & 2 deletions backend/supabase/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ select
contracts.last_updated_time,
contracts.last_bet_time,
contracts.last_comment_time,
contracts.is_politics,
contracts.freshness_score,
contracts.conversion_score,
contracts.view_count,
contracts.is_spice_payout,
contracts.unique_bettor_count,
contracts.tier
contracts.tier,
contracts.daily_score
from
contracts
where
Expand Down
1 change: 0 additions & 1 deletion common/src/api/market-search-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const searchProps = z
topicSlug: z.string().regex(FIRESTORE_DOC_REF_ID_REGEX).optional(),
forYou: z.union([z.literal('1'), z.literal('0')]).default('0'),
creatorId: z.string().regex(FIRESTORE_DOC_REF_ID_REGEX).optional(),
isPolitics: z.coerce.boolean().optional(),
isPrizeMarket: z
.union([
z.literal('true'),
Expand Down
4 changes: 1 addition & 3 deletions common/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ export type Contract<T extends AnyContractType = AnyContractType> = {

/** @deprecated - no more auto-subsidization */
isSubsidized?: boolean // NOTE: not backfilled, undefined = true
/** @deprecated - no more auto-subsidization */
isPolitics?: boolean
/** @deprecated - not kept up-to-date */
/** @deprecated - try to use group-contracts table instead */
groupSlugs?: string[]
/** @deprecated - not deprecated, only updated in supabase though*/
popularityScore: number
Expand Down
Loading

0 comments on commit 852dd49

Please sign in to comment.