Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
1895a5bc
Commit
1895a5bc
authored
Mar 18, 2016
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户等级加入缓存
parent
b867602e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
46 deletions
+71
-46
app.js
app.js
+1
-0
cacheable.js
app/utils/cacheable.js
+0
-1
loadUserLevel.js
app/utils/loadUserLevel.js
+26
-0
util.js
app/utils/util.js
+40
-43
cacheConfig.js
config/cacheConfig.js
+4
-2
No files found.
app.js
View file @
1895a5bc
...
...
@@ -39,4 +39,5 @@ mongoModels.forEach(function(model) {
global
.
mongodb
=
mongodb
;
require
(
'./config/express'
)(
app
,
config
);
require
(
'./config/cacheConfig'
);
app
.
listen
(
config
.
port
);
\ No newline at end of file
app/utils/cacheable.js
View file @
1895a5bc
...
...
@@ -17,7 +17,6 @@ function toCache(dur, k, v) {
if
(
str
){
redis
.
set
(
k
,
str
,
function
(
err
){
if
(
!
err
){
console
.
log
(
'缓存过期时间:'
,
dur
.
dur
);
redis
.
expire
(
k
,
dur
.
dur
);
}
});
...
...
app/utils/loadUserLevel.js
0 → 100644
View file @
1895a5bc
var
_
=
require
(
'lodash'
);
var
request
=
require
(
'request'
);
var
env
=
process
.
env
.
NODE_ENV
;
var
API_ADDRESS
=
'http://localhost:8080'
;
if
(
env
==
'sandbox'
)
{
API_ADDRESS
=
'http://rest.wxpai.cn'
;
}
else
if
(
env
==
'production'
)
{
API_ADDRESS
=
'https://rest.wxpai.cn'
;
}
exports
.
loadLevelFromAPI
=
function
(
ent_code
,
open_id
,
callback
){
if
(
!
ent_code
||
!
open_id
){
return
callback
&&
callback
(
null
,
null
);
}
var
url
=
API_ADDRESS
+
'/v1.0/internal/member/exp/byopenid?openId='
+
open_id
+
'&entCode='
+
ent_code
;
request
.
get
({
url
:
url
,
json
:
{}
},
function
(
e
,
r
,
body
)
{
if
(
e
)
{
console
.
log
(
e
)
}
return
callback
&&
callback
(
null
,(
body
&&
body
.
data
)
||
null
);
});
};
\ No newline at end of file
app/utils/util.js
View file @
1895a5bc
'use strict'
;
var
_
=
require
(
'lodash'
);
var
request
=
require
(
'request'
);
var
env
=
process
.
env
.
NODE_ENV
;
var
API_ADDRESS
=
'http://localhost:8080'
;
if
(
env
==
'sandbox'
)
{
API_ADDRESS
=
'http://rest.wxpai.cn'
;
}
else
if
(
env
==
'production'
)
{
API_ADDRESS
=
'https://rest.wxpai.cn'
;
}
var
loadUserLevel
=
require
(
'./loadUserLevel'
);
var
async
=
require
(
'async'
);
exports
.
loadLevel
=
function
(
ent_code
,
items
,
callback
){
var
openIds
=
[];
...
...
@@ -30,33 +24,35 @@ exports.loadLevel=function(ent_code,items,callback){
}
});
request
.
post
({
url
:
API_ADDRESS
+
'/v1.0/internal/member/list/byopenids'
,
json
:
{
"entCode"
:
ent_code
,
"openIds"
:
openIds
}
},
function
(
e
,
r
,
body
)
{
if
(
body
&&
body
.
data
)
{
var
tasks
=
[];
_
.
forEach
(
openIds
,
function
(
open_id
)
{
tasks
.
push
(
function
(
cont
)
{
loadUserLevel
.
loadLevelFromAPI
(
ent_code
,
open_id
,
cont
);
});
});
async
.
parallel
(
tasks
,
function
(
err
,
results
)
{
if
(
results
&&
results
.
length
>
0
)
{
//results: [{'egwegweg':1},{'gergergerg':3}]
_
.
forEach
(
items
,
function
(
d
,
i
)
{
if
(
items
[
i
].
toObject
)
{
items
[
i
]
=
items
[
i
].
toObject
();
}
_
.
forEach
(
body
.
data
,
function
(
r
,
j
)
{
if
(
d
.
from
&&
d
.
from
.
uid
===
r
.
user
.
openId
){
items
[
i
].
from
.
exp
=
r
.
exp
;
}
if
(
d
.
to
&&
d
.
to
.
uid
===
r
.
user
.
openId
){
items
[
i
].
to
.
exp
=
r
.
exp
;
}
if
(
d
.
commentLevel1From
&&
d
.
commentLevel1From
.
uid
===
r
.
user
.
openId
){
items
[
i
].
commentLevel1From
.
exp
=
r
.
exp
;
}
if
(
d
.
commentLevel2From
&&
d
.
commentLevel2From
.
uid
===
r
.
user
.
openId
){
items
[
i
].
commentLevel2From
.
exp
=
r
.
exp
;
}
if
(
d
.
commentLevel2ThreadFrom
&&
d
.
commentLevel2ThreadFrom
.
uid
===
r
.
user
.
openId
){
items
[
i
].
commentLevel2ThreadFrom
.
exp
=
r
.
exp
;
_
.
forEach
(
results
,
function
(
r
,
j
)
{
if
(
r
){
if
(
d
.
from
&&
d
.
from
.
uid
&&
r
[
d
.
from
.
uid
]){
items
[
i
].
from
.
exp
=
r
[
d
.
from
.
uid
];
}
if
(
d
.
to
&&
d
.
to
.
uid
&&
r
[
d
.
to
.
uid
]){
items
[
i
].
to
.
exp
=
r
[
d
.
to
.
uid
];
}
if
(
d
.
commentLevel1From
&&
d
.
commentLevel1From
.
uid
&&
r
[
d
.
commentLevel1From
.
uid
]){
items
[
i
].
commentLevel1From
.
exp
=
r
[
d
.
commentLevel1From
.
uid
];
}
if
(
d
.
commentLevel2From
&&
d
.
commentLevel2From
.
uid
&&
r
[
d
.
commentLevel2From
.
uid
]){
items
[
i
].
commentLevel2From
.
exp
=
r
[
d
.
commentLevel2From
.
uid
];
}
if
(
d
.
commentLevel2ThreadFrom
&&
d
.
commentLevel2ThreadFrom
.
uid
&&
r
[
d
.
commentLevel2ThreadFrom
.
uid
]){
items
[
i
].
commentLevel2ThreadFrom
.
exp
=
r
[
d
.
commentLevel2ThreadFrom
.
uid
];
}
}
});
...
...
@@ -88,22 +84,23 @@ exports.loadLevelByUser=function(ent_code,items,callback){
openIds
.
push
(
d
.
uid
);
}
});
request
.
post
({
url
:
API_ADDRESS
+
'/v1.0/internal/member/list/byopenids'
,
json
:
{
"entCode"
:
ent_code
,
"openIds"
:
openIds
}
},
function
(
e
,
r
,
body
)
{
if
(
body
&&
body
.
data
)
{
var
tasks
=
[];
_
.
forEach
(
openIds
,
function
(
open_id
)
{
tasks
.
push
(
function
(
cont
){
loadUserLevel
.
loadLevelFromAPI
(
ent_code
,
open_id
,
cont
);
});
});
async
.
parallel
(
tasks
,
function
(
err
,
results
){
if
(
results
&&
results
.
length
>
0
)
{
//results: [{'egwegweg':1},{'gergergerg':3}]
_
.
forEach
(
items
,
function
(
d
,
i
)
{
if
(
items
[
i
].
toObject
)
{
items
[
i
]
=
items
[
i
].
toObject
();
}
_
.
forEach
(
body
.
data
,
function
(
r
,
j
)
{
if
(
d
.
uid
===
r
.
user
.
openId
){
items
[
i
].
exp
=
r
.
exp
;
_
.
forEach
(
results
,
function
(
r
)
{
if
(
r
){
if
(
d
.
uid
&&
r
[
d
.
uid
]){
items
[
i
].
exp
=
r
[
d
.
uid
];
}
}
});
...
...
config/cacheConfig.js
View file @
1895a5bc
var
cache
=
require
(
'./../app/utils/cacheable'
);
var
forumAboutMEService
=
require
(
'./../app/service/forumAboutMEService'
);
var
loadUserLevel
=
require
(
'./../app/utils/loadUserLevel'
);
cache
.
cacheable
(
forumAboutMEService
,
'me2other'
,
{
ns
:
'forum.service.forumAboutMEService.me2other8'
,
dur
:
60
*
10
});
cache
.
cacheable
(
forumAboutMEService
,
'me2other'
,
{
ns
:
'forum.service.forumAboutMEService.me2other5'
,
dur
:
1
0
});
cache
.
cacheable
(
loadUserLevel
,
'loadLevelFromAPI'
,
{
ns
:
'forum.utils.loadUserLevel.loadLevelFromAPI68'
,
dur
:
60
*
6
0
});
//cache.clear(forumAboutMEService,'me2other','forum.service.forumAboutMEService222')
\ No newline at end of file
//cache.clear(service1,'method1','forum.service.service1.method1')
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment