use count(*) instead of count(id) since it's slightly faster
This commit is contained in:
parent
de103423e3
commit
876d12fc9d
@ -160,7 +160,7 @@ async function getAdmin(match, params) {
|
||||
}
|
||||
|
||||
query.leftJoin(
|
||||
knex("links").select("domain_id").count("id as links_count").groupBy("domain_id").as("l"),
|
||||
knex("links").select("domain_id").count("* as links_count").groupBy("domain_id").as("l"),
|
||||
"domains.id",
|
||||
"l.domain_id"
|
||||
);
|
||||
@ -195,7 +195,7 @@ async function totalAdmin(match, params) {
|
||||
|
||||
if (params?.links !== undefined) {
|
||||
query.leftJoin(
|
||||
knex("links").select("domain_id").count("id as links_count").groupBy("domain_id").as("l"),
|
||||
knex("links").select("domain_id").count("* as links_count").groupBy("domain_id").as("l"),
|
||||
"domains.id",
|
||||
"l.domain_id"
|
||||
);
|
||||
@ -203,7 +203,7 @@ async function totalAdmin(match, params) {
|
||||
}
|
||||
|
||||
query.leftJoin("users", "domains.user_id", "users.id");
|
||||
query.count("domains.id as count");
|
||||
query.count("* as count");
|
||||
|
||||
const [{ count }] = await query;
|
||||
|
||||
|
@ -70,7 +70,7 @@ async function total(match, params) {
|
||||
);
|
||||
}
|
||||
query.leftJoin("domains", "links.domain_id", "domains.id");
|
||||
query.count("links.id as count");
|
||||
query.count("* as count");
|
||||
|
||||
const [{ count }] = await query;
|
||||
|
||||
@ -106,7 +106,7 @@ async function totalAdmin(match, params) {
|
||||
|
||||
query.leftJoin("domains", "links.domain_id", "domains.id");
|
||||
query.leftJoin("users", "links.user_id", "users.id");
|
||||
query.count("links.id as count");
|
||||
query.count("* as count");
|
||||
|
||||
const [{ count }] = await query;
|
||||
|
||||
|
@ -169,7 +169,7 @@ async function getAdmin(match, params) {
|
||||
"d.user_id"
|
||||
)
|
||||
query.leftJoin(
|
||||
knex("links").select("user_id").count("id as links_count").groupBy("user_id").as("l"),
|
||||
knex("links").select("user_id").count("* as links_count").groupBy("user_id").as("l"),
|
||||
"users.id",
|
||||
"l.user_id"
|
||||
);
|
||||
@ -179,7 +179,7 @@ async function getAdmin(match, params) {
|
||||
|
||||
async function totalAdmin(match, params) {
|
||||
const query = knex("users")
|
||||
.count("users.id as count")
|
||||
.count("* as count")
|
||||
.fromRaw('users')
|
||||
.where(normalizeMatch(match));
|
||||
|
||||
@ -209,13 +209,13 @@ async function totalAdmin(match, params) {
|
||||
if (params?.links !== undefined) {
|
||||
query.andWhere("links", params?.links ? "is not" : "is", null);
|
||||
query.leftJoin(
|
||||
knex("links").select("user_id").count("id as links").groupBy("user_id").as("l"),
|
||||
knex("links").select("user_id").count("* as links").groupBy("user_id").as("l"),
|
||||
"users.id",
|
||||
"l.user_id"
|
||||
);
|
||||
}
|
||||
|
||||
const [{count}] = await query;
|
||||
const [{ count }] = await query;
|
||||
|
||||
return typeof count === "number" ? count : parseInt(count);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user