[copr] bkabrda-workspace: Add build counts to copr model to make things faster and easier to query (6d34286)
bkabrda at fedoraproject.org
bkabrda at fedoraproject.org
Mon Nov 19 07:03:02 UTC 2012
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : bkabrda-workspace
>---------------------------------------------------------------
commit 6d34286f730c3281631c86afc89fa19fa0c66452
Author: Bohuslav Kabrda <bkabrda at redhat.com>
Date: Mon Nov 19 07:57:31 2012 +0100
Add build counts to copr model to make things faster and easier to query
>---------------------------------------------------------------
...b_setup.py => 17aef4202992_initial_db_setup.py} | 25 ++++++++++---------
wsgi/coprs/models.py | 2 +
wsgi/coprs/templates/coprs/show.html | 2 +-
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/wsgi/alembic/versions/2cb3b8a9de3a_initial_db_setup.py b/wsgi/alembic/versions/17aef4202992_initial_db_setup.py
similarity index 94%
rename from wsgi/alembic/versions/2cb3b8a9de3a_initial_db_setup.py
rename to wsgi/alembic/versions/17aef4202992_initial_db_setup.py
index 3435690..3d8ce25 100644
--- a/wsgi/alembic/versions/2cb3b8a9de3a_initial_db_setup.py
+++ b/wsgi/alembic/versions/17aef4202992_initial_db_setup.py
@@ -1,13 +1,13 @@
"""Initial db setup
-Revision ID: 2cb3b8a9de3a
+Revision ID: 17aef4202992
Revises: None
-Create Date: 2012-11-16 11:38:30.605131
+Create Date: 2012-11-18 16:05:02.407902
"""
# revision identifiers, used by Alembic.
-revision = '2cb3b8a9de3a'
+revision = '17aef4202992'
down_revision = None
from alembic import op
@@ -27,10 +27,19 @@ def upgrade():
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('chroots', sa.Text(), nullable=False),
sa.Column('repos', sa.Text(), nullable=True),
+ sa.Column('build_count', sa.Integer(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
+ op.create_table('copr_permission',
+ sa.Column('approved', sa.Boolean(), nullable=True),
+ sa.Column('user_id', sa.Integer(), nullable=False),
+ sa.Column('copr_id', sa.Integer(), nullable=False),
+ sa.ForeignKeyConstraint(['copr_id'], ['copr.id'], ),
+ sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
+ sa.PrimaryKeyConstraint('user_id', 'copr_id')
+ )
op.create_table('build',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pkgs', sa.Text(), nullable=True),
@@ -49,21 +58,13 @@ def upgrade():
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
- op.create_table('copr_permission',
- sa.Column('approved', sa.Boolean(), nullable=True),
- sa.Column('user_id', sa.Integer(), nullable=False),
- sa.Column('copr_id', sa.Integer(), nullable=False),
- sa.ForeignKeyConstraint(['copr_id'], ['copr.id'], ),
- sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
- sa.PrimaryKeyConstraint('user_id', 'copr_id')
- )
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
- op.drop_table('copr_permission')
op.drop_table('build')
+ op.drop_table('copr_permission')
op.drop_table('copr')
op.drop_table('user')
### end Alembic commands ###
diff --git a/wsgi/coprs/models.py b/wsgi/coprs/models.py
index cce24da..1061678 100644
--- a/wsgi/coprs/models.py
+++ b/wsgi/coprs/models.py
@@ -86,6 +86,8 @@ class Copr(db.Model, Serializer):
name = db.Column(db.String(100), nullable = False)
chroots = db.Column(db.Text, nullable = False)
repos = db.Column(db.Text)
+ # duplicate information, but speeds up a lot and makes queries simpler
+ build_count = db.Column(db.Integer, default = 0)
# relations
owner_id = db.Column(db.Integer, db.ForeignKey('user.id'))
diff --git a/wsgi/coprs/templates/coprs/show.html b/wsgi/coprs/templates/coprs/show.html
index 24e146d..1bbec24 100644
--- a/wsgi/coprs/templates/coprs/show.html
+++ b/wsgi/coprs/templates/coprs/show.html
@@ -8,7 +8,7 @@
<div class=copr>
<h2><a href="{{ url_for('coprs_ns.copr_detail', username = copr.owner.name, coprname = copr.name) }}">{{ copr.owner.name }}/{{ copr.name }}</a></h2>
chroots: {{ copr.chroots_list|join(', ') }}<br>
- builds: {{ build_counts[loop.index0] }}<br>
+ builds: {{ copr.build_count }}<br>
{% if copr.repos %}
repos: {{ copr.repos_list|length }}
{% endif %}
More information about the copr-devel
mailing list