From 973696b0c50f235cfcef9e0cb30c6fc2f1028058 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 25 Jun 2018 17:18:34 -0400 Subject: [PATCH] add an index for the story_storytags table Queries that look for stories with tags take significant amount of time without this change. One trivial query for active stories with one tag dropped from 7m19s to 2.7s. Story: #2001939 Task: #15055 Change-Id: Id1783a3cf355f11b2037f4e0ada9514993820bca Signed-off-by: Doug Hellmann --- .../versions/063_index_story_storytags.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 storyboard/db/migration/alembic_migrations/versions/063_index_story_storytags.py diff --git a/storyboard/db/migration/alembic_migrations/versions/063_index_story_storytags.py b/storyboard/db/migration/alembic_migrations/versions/063_index_story_storytags.py new file mode 100644 index 00000000..08fbfe85 --- /dev/null +++ b/storyboard/db/migration/alembic_migrations/versions/063_index_story_storytags.py @@ -0,0 +1,36 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""index story_storytags + +Revision ID: a6e048164572 +Revises: 062 +Create Date: 2018-06-25 17:13:43.992561 + +""" + +# revision identifiers, used by Alembic. +revision = '063' +down_revision = '062' + + +from alembic import op + + +def upgrade(active_plugins=None, options=None): + op.create_index('story_storytags_idx', + 'story_storytags', ['story_id']) + + +def downgrade(active_plugins=None, options=None): + op.drop_index('story_storytags_idx')