Skip to content

Commit

Permalink
Add filters to optimize request times
Browse files Browse the repository at this point in the history
  • Loading branch information
hualiong committed Jun 18, 2024
1 parent ef8bc7a commit 6fa09cd
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions lib/routes/sicau/jk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,31 @@ export const route: Route = {
headers: { 'x-access-token': token },
method: 'post',
});

const { code, message, content } = await $post(`/getUserSchoolActList`, {
query: {
gid: gidDict[gid],
typeId: typeDict[typeId],
sortType,
page: 1,
},
});

if (code !== '0') {
throw new Error(message);
const query = async (page: number) =>
await $post(`/getUserSchoolActList`, {
query: {
gid: gidDict[gid],
typeId: typeDict[typeId],
sortType,
page,
},
});

const res1 = await query(1);
const res2 = await query(2);

if (res1.code !== '0' || res2.code !== '0') {
throw new Error(`${res1.message} | ${res2.message}`);
}

const list: DataItem[] = content.map((each) => ({
id: each.id,
guid: each.id,
title: each.title,
image: each.logo,
pubDate: timezone(parseDate(each.startTime, 'YYYY-MM-DD HH:mm:ss'), +8),
}));
const list: DataItem[] = [...res1.content, ...res2.content]
.filter((e) => e.statusName !== '待发学时')
.map((each) => ({
id: each.id,
guid: each.id,
title: each.title,
image: each.logo,
}));

const items = await Promise.all(
list.map((item) =>
Expand Down

0 comments on commit 6fa09cd

Please sign in to comment.