Skip to content

Stats speedup#588

Open
ciaran wants to merge 5 commits intoAdmiralGT:mainfrom
ciaran:stats-speedup
Open

Stats speedup#588
ciaran wants to merge 5 commits intoAdmiralGT:mainfrom
ciaran:stats-speedup

Conversation

@ciaran
Copy link
Copy Markdown
Contributor

@ciaran ciaran commented Sep 28, 2025

#586 sped up stats load but it’s still very slow. Without real data I’ve not been able to reproduce the load time locally but I think this change should help.

scripts/views.py Outdated
character_count[type.value] = Counter()
num_count[type.value] = Counter()

character_counts = queries.get_all_script_character_counts()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

issue I believe you've lost all of the prior queryset filtering that has occurred with the change. The statistics page can also have parameterised filtering (albeit it's not the most common usage).

cursor.execute("""
SELECT character_type->>'id' AS character, COUNT(1) AS count
FROM "scripts_scriptversion"
CROSS JOIN LATERAL jsonb_array_elements(content) character_type
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

nitpick I'm really not keen on the use of "character_type" here as a name as that is a specific clocktower term and this isn't related to that terminology.

suggestion I'd use character_instance rather than _type as the representation.

@ciaran
Copy link
Copy Markdown
Contributor Author

ciaran commented Oct 11, 2025

Unfortunately I don’t know Django at all, I did try to research but I couldn't see a way to achieve this query in the ORM syntax so I’ve just opted to embed the queryset SQL as a subquery here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants