feat: 优化统计信息获取逻辑
This commit is contained in:
parent
8f40de1682
commit
6cb7a26ad5
@ -31,6 +31,7 @@ const getStatisticsInfo = async () => {
|
||||
const prevWeekInfo = await db.view.getFullStatisticsByWeek(
|
||||
getPrevWeekWithYear()
|
||||
);
|
||||
if (!curWeekInfo || !prevWeekInfo) return {};
|
||||
return {
|
||||
total_count: String(curWeekInfo?.total_count ?? 0),
|
||||
weekly_count_rate: calculateWeeklyRate(
|
||||
@ -51,12 +52,10 @@ const getStatisticsInfo = async () => {
|
||||
};
|
||||
|
||||
const getProjDiffInfo = async () => {
|
||||
const curWeekInfo = await db.view.getProjStatisticsByWeek(
|
||||
getWeekTimeWithYear()
|
||||
) || [];
|
||||
const prevWeekInfo = await db.view.getProjStatisticsByWeek(
|
||||
getPrevWeekWithYear()
|
||||
) || [];
|
||||
const curWeekInfo =
|
||||
(await db.view.getProjStatisticsByWeek(getWeekTimeWithYear())) || [];
|
||||
const prevWeekInfo =
|
||||
(await db.view.getProjStatisticsByWeek(getPrevWeekWithYear())) || [];
|
||||
|
||||
const group: {
|
||||
project_name: string;
|
||||
|
@ -18,23 +18,23 @@ export interface PipelineRecordModel extends RecordModel {
|
||||
}
|
||||
|
||||
const getOne = (id: string) =>
|
||||
managePb404(
|
||||
managePb404<PipelineRecordModel>(
|
||||
async () => await pbClient.collection("pipeline").getOne(id)
|
||||
) as Promise<PipelineRecordModel>;
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取项目最新一次构建
|
||||
* @param project_id 项目id
|
||||
*/
|
||||
const getLatestOne = (project_id: string) => {
|
||||
return managePb404(
|
||||
return managePb404<PipelineRecordModel>(
|
||||
async () =>
|
||||
await pbClient
|
||||
.collection("pipeline")
|
||||
.getFirstListItem(`project_id="${project_id}"`, {
|
||||
sort: "-created_at",
|
||||
})
|
||||
) as Promise<PipelineRecordModel>;
|
||||
);
|
||||
};
|
||||
|
||||
const create = async (data: Partial<PipelineRecordModel>) =>
|
||||
|
@ -13,9 +13,9 @@ export interface ProjectRecordModel extends RecordModel {
|
||||
}
|
||||
|
||||
const getOne = (id: string) =>
|
||||
managePb404(
|
||||
managePb404<ProjectRecordModel>(
|
||||
async () => await pbClient.collection("project").getOne(id)
|
||||
) as Promise<ProjectRecordModel>;
|
||||
);
|
||||
|
||||
const getFullList = async () =>
|
||||
await pbClient.collection("project").getFullList<ProjectRecordModel>();
|
||||
|
@ -11,19 +11,19 @@ export interface UserRecordModel extends RecordModel {
|
||||
}
|
||||
|
||||
const getOne = (id: string) =>
|
||||
managePb404(
|
||||
managePb404<UserRecordModel>(
|
||||
async () => await pbClient.collection("user").getOne(id)
|
||||
) as Promise<UserRecordModel>;
|
||||
);
|
||||
|
||||
const getOneByUserId = (user_id: number) => {
|
||||
return managePb404(
|
||||
return managePb404<UserRecordModel>(
|
||||
async () =>
|
||||
await pbClient
|
||||
.collection("user")
|
||||
.getFirstListItem(`user_id="${user_id}"`, {
|
||||
sort: "-created",
|
||||
})
|
||||
) as Promise<UserRecordModel>;
|
||||
);
|
||||
};
|
||||
|
||||
const create = async (data: Partial<UserRecordModel>) =>
|
||||
|
@ -19,21 +19,21 @@ export interface StatisticsPerProjRecordModel extends RecordModel {
|
||||
}
|
||||
|
||||
const getFullStatisticsByWeek = (week: string) => {
|
||||
return managePb404(
|
||||
return managePb404<StatisticsPerWeekRecordModel>(
|
||||
async () =>
|
||||
await pbClient
|
||||
.collection("statisticsPerWeek")
|
||||
.getFirstListItem(`week="${week}"`)
|
||||
) as Promise<StatisticsPerWeekRecordModel>;
|
||||
);
|
||||
};
|
||||
|
||||
const getProjStatisticsByWeek = (week: string) => {
|
||||
return managePb404(
|
||||
return managePb404<StatisticsPerProjRecordModel[]>(
|
||||
async () =>
|
||||
await pbClient
|
||||
.collection("statisticsPerProj")
|
||||
.getFullList({ filter: `week="${week}"` })
|
||||
) as Promise<StatisticsPerProjRecordModel[]>;
|
||||
);
|
||||
};
|
||||
|
||||
const view = {
|
||||
|
@ -1,8 +1,7 @@
|
||||
export const managePb404 = async (dbFunc: Function) => {
|
||||
export const managePb404 = async <T>(dbFunc: Function): Promise<T | null> => {
|
||||
try {
|
||||
return await dbFunc();
|
||||
} catch (err: any) {
|
||||
// 没有这个提醒就返回空
|
||||
if (err?.message === "The requested resource wasn't found.") {
|
||||
return null;
|
||||
} else throw err;
|
||||
|
Loading…
x
Reference in New Issue
Block a user