Spaces:
Sleeping

PERDYPTO commited on
Commit
25395b0
·
verified ·
1 Parent(s): 0f70988

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -89,7 +89,9 @@ async def get_repos(
89
  offset: int = Query(0, ge=0)
90
  ):
91
  db = get_db()
92
- query = "SELECT repo_id, full_name, description, stars, forks_count, is_fork, archived, primary_language, pushed_at FROM metadata WHERE 1=1"
 
 
93
  count_query = "SELECT COUNT(*) FROM metadata WHERE 1=1"
94
  params = []
95
 
@@ -114,20 +116,24 @@ async def get_repos(
114
  count_query += " AND primary_language = ?"
115
  params.append(language)
116
  if search:
117
- query += " AND (full_name LIKE ? OR description LIKE ?)"
118
- count_query += " AND (full_name LIKE ? OR description LIKE ?)"
119
  params.extend([f"%{search}%", f"%{search}%"])
120
 
121
  # Get total count for pagination UI
122
  total = db.execute(count_query, params).fetchone()[0]
123
 
124
  # Validate sort to prevent SQL injection
125
- allowed_sorts = ["stars", "forks_count", "pushed_at", "full_name"]
126
  if sort_by not in allowed_sorts:
127
  sort_by = "stars"
128
  sort_dir = "ASC" if sort_dir.lower() == "asc" else "DESC"
129
 
130
- query += f" ORDER BY {sort_by} {sort_dir} LIMIT ? OFFSET ?"
 
 
 
 
131
 
132
  repos = db.execute(query, params + [limit, offset]).fetchall()
133
  db.close()
 
89
  offset: int = Query(0, ge=0)
90
  ):
91
  db = get_db()
92
+
93
+ # Use resolved_parent_path and alias it as full_name for the frontend
94
+ query = "SELECT repo_id, resolved_parent_path AS full_name, description, stars, forks_count, is_fork, archived, primary_language, pushed_at FROM metadata WHERE 1=1"
95
  count_query = "SELECT COUNT(*) FROM metadata WHERE 1=1"
96
  params = []
97
 
 
116
  count_query += " AND primary_language = ?"
117
  params.append(language)
118
  if search:
119
+ query += " AND (resolved_parent_path LIKE ? OR description LIKE ?)"
120
+ count_query += " AND (resolved_parent_path LIKE ? OR description LIKE ?)"
121
  params.extend([f"%{search}%", f"%{search}%"])
122
 
123
  # Get total count for pagination UI
124
  total = db.execute(count_query, params).fetchone()[0]
125
 
126
  # Validate sort to prevent SQL injection
127
+ allowed_sorts = ["stars", "forks_count", "pushed_at", "resolved_parent_path"]
128
  if sort_by not in allowed_sorts:
129
  sort_by = "stars"
130
  sort_dir = "ASC" if sort_dir.lower() == "asc" else "DESC"
131
 
132
+ # Replace full_name with resolved_parent_path for sorting
133
+ if sort_by == "resolved_parent_path":
134
+ query += f" ORDER BY resolved_parent_path {sort_dir} LIMIT ? OFFSET ?"
135
+ else:
136
+ query += f" ORDER BY {sort_by} {sort_dir} LIMIT ? OFFSET ?"
137
 
138
  repos = db.execute(query, params + [limit, offset]).fetchall()
139
  db.close()