-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IND-467] Push ender market create logic to use a single sql function #737
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||||||||||
CREATE OR REPLACE FUNCTION dydx_market_create_handler(event_data jsonb) RETURNS jsonb AS $$ | ||||||||||||||
DECLARE | ||||||||||||||
market_record_id integer; | ||||||||||||||
market_record markets%ROWTYPE; | ||||||||||||||
BEGIN | ||||||||||||||
market_record_id = (event_data->'marketId')::integer; | ||||||||||||||
SELECT * INTO market_record FROM markets WHERE "id" = market_record_id; | ||||||||||||||
|
||||||||||||||
IF FOUND THEN | ||||||||||||||
RAISE EXCEPTION 'Market in MarketCreate already exists. Record: %', market_record; | ||||||||||||||
END IF; | ||||||||||||||
Comment on lines
+16
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message in the exception is clear and provides useful information for debugging. However, consider adding more context to the error message, such as the event data that caused the exception. This can help with debugging if the error occurs. - RAISE EXCEPTION 'Market in MarketCreate already exists. Record: %', market_record;
+ RAISE EXCEPTION 'Market in MarketCreate already exists. Event data: %, Record: %', event_data, market_record; Commitable suggestion (Beta)
Suggested change
|
||||||||||||||
|
||||||||||||||
market_record."id" = market_record_id; | ||||||||||||||
market_record."pair" = event_data->'marketCreate'->'base'->>'pair'; | ||||||||||||||
market_record."exponent" = (event_data->'marketCreate'->'exponent')::integer; | ||||||||||||||
market_record."minPriceChangePpm" = (event_data->'marketCreate'->'base'->'minPriceChangePpm')::integer; | ||||||||||||||
|
||||||||||||||
INSERT INTO markets VALUES (market_record.*); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - INSERT INTO markets VALUES (market_record.*);
+ INSERT INTO markets (id, pair, exponent, minPriceChangePpm) VALUES (market_record.id, market_record.pair, market_record.exponent, market_record.minPriceChangePpm); Commitable suggestion (Beta)
Suggested change
|
||||||||||||||
|
||||||||||||||
RETURN jsonb_build_object( | ||||||||||||||
'market', | ||||||||||||||
dydx_to_jsonb(market_record) | ||||||||||||||
); | ||||||||||||||
END; | ||||||||||||||
$$ LANGUAGE plpgsql; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
updateMarket
function directly modifies theidToMarket
map. This could potentially lead to data races if multiple threads are trying to update the map at the same time. Consider using a lock or other synchronization mechanism to ensure thread safety.Commitable suggestion (Beta)