Skip to content

(VDB-1064) Query historical_ilk_states table instead of using get_ilk#92

Merged
gslaughl merged 1 commit intostagingfrom
vdb-1064-replace-ilk-query
Jan 21, 2020
Merged

(VDB-1064) Query historical_ilk_states table instead of using get_ilk#92
gslaughl merged 1 commit intostagingfrom
vdb-1064-replace-ilk-query

Conversation

@gslaughl
Copy link
Copy Markdown
Contributor

This PR replaces the api.get_ilk function with queries to the more performant api.historical_ilk_state table. We're still using get_ilk in some of our tests (specifically the ilk_state computed columns tests), but once we refactor the all_ilks query to use historical_ilk_states, we should be able to delete the ilk_state type altogether, along with its computed columns.

@gslaughl gslaughl force-pushed the vdb-1064-replace-ilk-query branch from e184dea to fdb5f67 Compare January 16, 2020 15:44
-- +goose StatementBegin

-- Function returning the history of a given ilk as of the given block height
CREATE FUNCTION api.all_ilk_states(ilk_identifier TEXT, block_height BIGINT DEFAULT api.max_block(),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be totally obsolete now, since its functionality can replicated by filtering the allHistoricalIlkStates function that postgraphile exposes

Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressively small diff 😍

-- Extend frob_event with ilk_state
CREATE FUNCTION api.frob_event_ilk(event api.frob_event)
RETURNS api.ilk_state AS
RETURNS api.historical_ilk_state AS
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably missing something but I can't see where in the migrations the api.historical_ilk_state is defined 🤔

I see it in the schema but wanting to double check that the relevant migration (with the name change) was checked in

Copy link
Copy Markdown
Contributor Author

@gslaughl gslaughl Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, historical_ilk_state is the name of the trigger table.

https://github.com/makerdao/vdb-mcd-transformers/blob/vdb-1064-replace-ilk-query/db/migrations/20190301141224_create_ilk_state_history_table_and_triggers.sql#L2

It got moved around in the migration order, which is the only reason it's appearing in the schema diff

CreateCatRecords(db, header, valuesMap, catMetadatas, catRepo)
CreateJugRecords(db, header, valuesMap, jugMetadatas, jugRepo)
CreateSpotRecords(db, header, valuesMap, spotMetadatas, spotRepo)
if len(vatMetadatas) >= 1 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale behind this predicate? Are there places where we want to create metadata for non-vat contracts but not for the vat?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we're doing that a few times in the tests for get_ilk. E.g. https://github.com/makerdao/vdb-mcd-transformers/blob/vdb-1064-replace-ilk-query/transformers/component_tests/queries/get_ilk_query_test.go#L233

So I guess we could get rid of this conditional when we delete the get_ilk function, after the ilk_state type is deleted.

Copy link
Copy Markdown
Contributor

@rmulhol rmulhol Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. My initial thought is to wonder whether those tests correctly simulate realistic conditions, but I suppose it probably makes sense that we'd want to be able to verify that the records are correct even if some important data is missing.

@gslaughl gslaughl merged commit b8e8f3f into staging Jan 21, 2020
@gslaughl gslaughl deleted the vdb-1064-replace-ilk-query branch January 21, 2020 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants