Skip to content

Conversation

@Rader
Copy link
Collaborator

@Rader Rader commented Aug 25, 2025

Issue 1

Background

The SQL query used for the daily scheduled calculation of repository recommendation weights is performing a full table scan instead of using an index, leading to numerous slow queries.

Solution

Change the repository traversal method to traverse by repository ID order. Since the ID is an auto-incrementing value, sequential lookups are very fast.

Issue 2

Background

Queries using LOWER(path) = LOWER('AIWizards/whisper-base-mlx-2bit') bypass the index, resulting in many slow SQL queries.

Solution

Change the unique index of the repositories table from (repository_type, path) to (repository_type, lower(path)). This allows queries using LOWER(path) to hit the index.

Testing

Database migration scripts

Migration

init logger, level: INFO, format: json
{"time":"2025-08-19T12:11:17.17196+08:00","level":"INFO","msg":"migrated to group #140 (20250819034735_idx_repositories_repository_type_lower_path)"}

Rollback

{"time":"2025-08-19T12:11:58.424687+08:00","level":"INFO","msg":"rolled back group #140 (20250819034735_idx_repositories_repository_type_lower_path)"}

Copy link
Collaborator

@ganisback ganisback left a comment

Choose a reason for hiding this comment

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

LGTM

@Rader Rader merged commit 252bb4a into main Aug 26, 2025
6 checks passed
@Rader Rader deleted the cp-slow-sql branch August 26, 2025 08:10
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.

3 participants