From 638dbb3d8dbcbe4b1f76a8b695c74916d700f5ed Mon Sep 17 00:00:00 2001 From: jakedt Date: Wed, 5 Mar 2014 14:35:11 -0500 Subject: [PATCH] Cache the status tags and fix the tag for images that were pushed from a build. --- config.py | 24 +++++++++++++++++------- endpoints/web.py | 10 ++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/config.py b/config.py index 0b07d2689..aa9041325 100644 --- a/config.py +++ b/config.py @@ -1,6 +1,7 @@ import logging import logstash_formatter import requests +import os.path from peewee import MySQLDatabase, SqliteDatabase from storage.s3 import S3Storage @@ -205,9 +206,18 @@ class LargePoolHttpClient(object): HTTPCLIENT = build_requests_session() +class StatusTagConfig(object): + STATUS_TAGS = {} + + for tag_name in ['building', 'failed', 'none', 'ready']: + tag_path = os.path.join('buildstatus', tag_name + '.svg') + with open(tag_path) as tag_svg: + STATUS_TAGS[tag_name] = tag_svg.read() + + class TestConfig(FlaskConfig, FakeStorage, EphemeralDB, FakeUserfiles, FakeAnalytics, StripeTestConfig, RedisBuildLogs, - UserEventConfig, LargePoolHttpClient): + UserEventConfig, LargePoolHttpClient, StatusTagConfig): LOGGING_CONFIG = logs_init_builder(logging.WARN) POPULATE_DB_TEST_DATA = True TESTING = True @@ -218,7 +228,8 @@ class TestConfig(FlaskConfig, FakeStorage, EphemeralDB, FakeUserfiles, class DebugConfig(FlaskConfig, MailConfig, LocalStorage, SQLiteDB, StripeTestConfig, MixpanelTestConfig, GitHubTestConfig, DigitalOceanConfig, BuildNodeConfig, S3Userfiles, - UserEventConfig, TestBuildLogs, LargePoolHttpClient): + UserEventConfig, TestBuildLogs, LargePoolHttpClient, + StatusTagConfig): LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter()) SEND_FILE_MAX_AGE_DEFAULT = 0 POPULATE_DB_TEST_DATA = True @@ -230,7 +241,8 @@ class LocalHostedConfig(FlaskConfig, MailConfig, S3Storage, RDSMySQL, StripeLiveConfig, MixpanelTestConfig, GitHubProdConfig, DigitalOceanConfig, BuildNodeConfig, S3Userfiles, RedisBuildLogs, - UserEventConfig, LargePoolHttpClient): + UserEventConfig, LargePoolHttpClient, + StatusTagConfig): LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter()) SEND_FILE_MAX_AGE_DEFAULT = 0 URL_SCHEME = 'http' @@ -241,8 +253,7 @@ class StagingConfig(FlaskProdConfig, MailConfig, S3Storage, RDSMySQL, StripeLiveConfig, MixpanelProdConfig, GitHubStagingConfig, DigitalOceanConfig, BuildNodeConfig, S3Userfiles, RedisBuildLogs, UserEventConfig, - LargePoolHttpClient): - + LargePoolHttpClient, StatusTagConfig): LOGGING_CONFIG = logs_init_builder(formatter=logging.Formatter()) SEND_FILE_MAX_AGE_DEFAULT = 0 URL_SCHEME = 'https' @@ -253,8 +264,7 @@ class ProductionConfig(FlaskProdConfig, MailConfig, S3Storage, RDSMySQL, StripeLiveConfig, MixpanelProdConfig, GitHubProdConfig, DigitalOceanConfig, BuildNodeConfig, S3Userfiles, RedisBuildLogs, UserEventConfig, - LargePoolHttpClient): - + LargePoolHttpClient, StatusTagConfig): LOGGING_CONFIG = logs_init_builder() SEND_FILE_MAX_AGE_DEFAULT = 0 URL_SCHEME = 'https' diff --git a/endpoints/web.py b/endpoints/web.py index 0e0692480..122b35095 100644 --- a/endpoints/web.py +++ b/endpoints/web.py @@ -20,6 +20,7 @@ logger = logging.getLogger(__name__) web = Blueprint('web', __name__) +STATUS_TAGS = app.config['STATUS_TAGS'] @web.route('/', methods=['GET'], defaults={'path': ''}) @web.route('/organization/', methods=['GET']) @@ -211,7 +212,6 @@ def build_status_badge(namespace, repository): abort(404) # Lookup the tags for the repository. - tags = model.list_repository_tags(namespace, repository) # Lookup the current/recent build. status = 'none' @@ -220,16 +220,14 @@ def build_status_badge(namespace, repository): if build.phase == 'error': status = 'failed' elif build.phase == 'complete': - pass + status = 'ready' else: status = 'building' else: + tags = model.list_repository_tags(namespace, repository) if list(tags): status = 'ready' - with open(os.path.join(app.root_path, 'buildstatus', status + '.svg')) as f: - svg = f.read() - - response = make_response(svg) + response = make_response(STATUS_TAGS[status]) response.content_type = 'image/svg+xml' return response