Skip to content

utilize statscollector to estimate full table size #436

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/blueprints/spa_api/spa_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def encode_bot_name(w):
@bp.route('/global/replay_count')
@with_session
def api_get_replay_count(session=None):
count = session.query(Game.hash).count()
return jsonify(count)
result = session.execute(Game.count_query())
return jsonify(result.scalar())


@bp.route('/global/queue/count')
Expand Down
3 changes: 3 additions & 0 deletions backend/database/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def validate_code(self, key, value):
return value[:max_len]
return value

def count_query():
return "SELECT n_live_tup FROM pg_stat_all_tables WHERE relname = '%s'" % (Game.__table__.name)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of this way if inserting the table names we should be able to do this in SQL alchemy without the need of a custom string.

Copy link
Author

Choose a reason for hiding this comment

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

Totally agree, I'm really not a fan of this. I'll take another crack at it.



class Player(DBObjectBase):
__tablename__ = 'players'
Expand Down