mirror of
https://gitbruv.vercel.app/api/git/bruv/gitbruv.git
synced 2025-12-20 23:24:09 +01:00
add
This commit is contained in:
parent
2a92cf6f0a
commit
3504711521
2 changed files with 194 additions and 21 deletions
|
|
@ -801,3 +801,42 @@ export async function getUserStarredRepos(username: string) {
|
|||
},
|
||||
}));
|
||||
}
|
||||
|
||||
export async function getPublicUsers(sortBy: "newest" | "oldest" = "newest", limit: number = 20, offset: number = 0) {
|
||||
"use cache";
|
||||
cacheTag("public-users", `public-users:${sortBy}:${offset}`);
|
||||
cacheLife("minutes");
|
||||
|
||||
const allUsers = await db
|
||||
.select({
|
||||
id: users.id,
|
||||
name: users.name,
|
||||
username: users.username,
|
||||
image: users.image,
|
||||
avatarUrl: users.avatarUrl,
|
||||
bio: users.bio,
|
||||
createdAt: users.createdAt,
|
||||
repoCount: sql<number>`(SELECT COUNT(*) FROM repositories WHERE repositories.owner_id = ${users.id} AND repositories.visibility = 'public')`.as("repo_count"),
|
||||
})
|
||||
.from(users)
|
||||
.orderBy(sortBy === "newest" ? desc(users.createdAt) : users.createdAt)
|
||||
.limit(limit + 1)
|
||||
.offset(offset);
|
||||
|
||||
const hasMore = allUsers.length > limit;
|
||||
const result = allUsers.slice(0, limit);
|
||||
|
||||
return {
|
||||
users: result.map((u) => ({
|
||||
id: u.id,
|
||||
name: u.name,
|
||||
username: u.username,
|
||||
image: u.image,
|
||||
avatarUrl: u.avatarUrl,
|
||||
bio: u.bio,
|
||||
createdAt: u.createdAt,
|
||||
repoCount: Number(u.repoCount),
|
||||
})),
|
||||
hasMore,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue