-
Notifications
You must be signed in to change notification settings - Fork 650
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
Speedup query to do ApiKey grants #15927
Speedup query to do ApiKey grants #15927
Conversation
103a84b
to
2dd2796
Compare
2dd2796
to
9f0f892
Compare
end | ||
end | ||
|
||
user.db_service.sequences_for_tables(tables).each do |sequence| |
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 old sequences_for_table(schema, table_name)
did N queries to retrieve all the sequences for all the tables. The new user.db_service.sequences_for_tables(tables)
does the same but in a single query.
@@ -585,26 +591,6 @@ def remove_from_redis(key = redis_key) | |||
redis_client.del(key) | |||
end | |||
|
|||
def sequences_for_table(schema, table) |
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 new version of this (sequences_for_tables
) has been moved to the DB service.
|
||
describe '#public_user_roles' do | ||
subject { db_service.public_user_roles } | ||
subject(:public_user_roles) { db_service.public_user_roles } |
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.
These are mostly linter fixes, the important part is under describe '#sequences_for_tables' do
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.
LGTM 👍
Acceptance in staging ✅ API key creation continues to work as expected: {
"id": "75f6c827-6933-4b4f-bf9f-78e29aad4a2e",
"token": "JWTDtOqbc_d3IogeGIY4wQ",
"user_id": "8c8ec7bb-29a8-432c-90ee-5d2a1ae472de",
"type": "regular",
"name": "Test",
"db_role": "carto_role_94bb1a0408a21405ba67d88fbb21019b",
"db_password": "2063f7789c301dc4cc981c560ce0870a992eafdd",
"grants": [
{
"type": "apis",
"apis": [
"maps",
"sql"
]
},
{
"type": "database",
"tables": [
{
"name": "dataset_ciudades_2",
"schema": "amiedes-sequences1",
"permissions": [
"select",
"update",
"insert",
"delete"
]
},
{
"name": "dataset_ciudades",
"schema": "amiedes-sequences1",
"permissions": [
"select",
"update",
"insert",
"delete"
]
},
{
"name": "dataset_ciudades_1",
"schema": "amiedes-sequences1",
"permissions": [
"select",
"update",
"insert",
"delete"
]
}
],
"schemas": [
]
}
],
"created_at": "2020-12-09 09:53:51 UTC",
"updated_at": "2020-12-09 09:53:51 UTC"
} Will do more performance testing in production with the real application. |
Related: https://app.clubhouse.io/cartoteam/story/117080/performance-issues-with-datasets-r-scope
What does this PR do?
Previously, when generating the
GRANT
s associated to an API key, we were doing a query similar to the following to retrieve the sequences associated with each of the tables the API key had access to:For an API key with access to 150 tables, this query took ~200ms. This means for the 150 tables it was around 35 seconds.
This PR combines all the queries to retrieve the list of sequences to give the
GRANT
s in a single query, so it is faster:Now the same query takes ~2 seconds.