@@ -14,19 +14,22 @@ class IndexController extends controller {
14
14
qq_account as qqAccount, wechat_account as weChatAccount, github_url as githubUrl,
15
15
logo_name as logoName, logo_sub as logoSub
16
16
FROM admin_user WHERE id = ?` ;
17
- const selectResult = await this . app . mysql . query ( selectSql , [ id ] ) ;
18
- const articleCountResult = await this . app . mysql . query ( 'SELECT count(*) as count from article' ) ;
19
- const talkCountResult = await this . app . mysql . query ( 'SELECT count(*) as count from talk' ) ;
20
- const novelCountResult = await this . app . mysql . query ( 'SELECT count(*) as count from novel' ) ;
21
- if ( selectResult . length > 0 ) {
22
- const dataObj = selectResult [ 0 ] ;
23
- dataObj . articleCount = articleCountResult [ 0 ] . count ;
24
- dataObj . talkCount = talkCountResult [ 0 ] . count ;
25
- dataObj . novelCount = novelCountResult [ 0 ] . count ;
26
- this . ctx . body = { success : true , data : dataObj } ;
27
- } else {
28
- this . ctx . body = { success : false , message : '获取个人信息失败' } ;
29
- }
17
+ const userInfoPromise = this . app . mysql . query ( selectSql , [ id ] ) ;
18
+ const articleCountPromise = this . app . mysql . query ( 'SELECT count(*) as count from article' ) ;
19
+ const talkCountPromise = this . app . mysql . query ( 'SELECT count(*) as count from talk' ) ;
20
+ const novelCountPromise = this . app . mysql . query ( 'SELECT count(*) as count from novel' ) ;
21
+ Promise . all ( [ userInfoPromise , articleCountPromise , talkCountPromise , novelCountPromise ] )
22
+ . then ( ( [ userInfoResult , articleCountResult , talkCountResult , novelCountResult ] ) => {
23
+ if ( userInfoResult . length > 0 ) {
24
+ const dataObj = userInfoResult [ 0 ] ;
25
+ dataObj . articleCount = articleCountResult [ 0 ] . count ;
26
+ dataObj . talkCount = talkCountResult [ 0 ] . count ;
27
+ dataObj . novelCount = novelCountResult [ 0 ] . count ;
28
+ this . ctx . body = { success : true , data : dataObj } ;
29
+ } else {
30
+ this . ctx . body = { success : false , message : '获取个人信息失败' } ;
31
+ }
32
+ } )
30
33
}
31
34
32
35
async getAdverList ( ) {
@@ -53,25 +56,28 @@ class IndexController extends controller {
53
56
article_type.name as type
54
57
FROM article LEFT JOIN article_type
55
58
ON article.type_id = article_type.id WHERE article.is_publish = 1 ORDER BY article.publish_time DESC LIMIT ?,?` ;
56
- const result = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
57
- const countResult = await this . app . mysql . query ( 'SELECT count(*) as total FROM article' ) ;
58
- if ( result . length > 0 ) {
59
- for ( const item of result ) {
60
- item . listType = 'article' ;
59
+ const articleListPromise = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
60
+ const countPromise = await this . app . mysql . query ( 'SELECT count(*) as total FROM article' ) ;
61
+ Promise . all ( [ articleListPromise , countPromise ] )
62
+ . then ( ( [ articleListResult , countResult ] ) => {
63
+ if ( articleListResult . length > 0 ) {
64
+ for ( const item of articleListResult ) {
65
+ item . listType = 'article' ;
66
+ }
67
+ this . ctx . body = {
68
+ success : true ,
69
+ data : {
70
+ total : countResult [ 0 ] . total ,
71
+ list : articleListResult ,
72
+ } ,
73
+ } ;
74
+ } else {
75
+ this . ctx . body = {
76
+ success : false ,
77
+ message : '获取文章列表失败' ,
78
+ } ;
61
79
}
62
- this . ctx . body = {
63
- success : true ,
64
- data : {
65
- total : countResult [ 0 ] . total ,
66
- list : result ,
67
- } ,
68
- } ;
69
- } else {
70
- this . ctx . body = {
71
- success : false ,
72
- message : '获取文章列表失败' ,
73
- } ;
74
- }
80
+ } )
75
81
}
76
82
77
83
async getTalkList ( ) {
0 commit comments