Skip to content

Commit

Permalink
feat: 大幅度优化首页加载速度
Browse files Browse the repository at this point in the history
  • Loading branch information
苏文雄 committed Aug 23, 2019
1 parent 68a530c commit 6dab9fa
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 23 deletions.
7 changes: 6 additions & 1 deletion client/containers/Project/Interface/Interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ const InterfaceRoute = props => {
C = InterfaceColContent;
} else if (props.match.params.action === 'case') {
C = InterfaceCaseContent;
} else {
const params = props.match.params;
props.history.replace('/project/' + params.id + '/interface/api');
return null;
}
return <C {...props} />;
};

InterfaceRoute.propTypes = {
match: PropTypes.object
match: PropTypes.object,
history: PropTypes.object
};

@connect(
Expand Down
7 changes: 5 additions & 2 deletions client/reducer/modules/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default (state = initialState, action) => {
case SET_CURR_GROUP: {
return {
...state,
currGroup: action.payload
currGroup: action.payload.data.data
};
}
case FETCH_GROUP_MEMBER: {
Expand All @@ -58,6 +58,7 @@ export default (state = initialState, action) => {
};
}
case FETCH_GROUP_MSG: {
console.log(action.payload)
// const {role,group_name,group_desc,} = action.payload.data.data
return {
...state,
Expand Down Expand Up @@ -154,6 +155,8 @@ export function fetchGroupList() {
export function setCurrGroup(group) {
return {
type: SET_CURR_GROUP,
payload: group
payload: axios.get('/api/group/get', {
params: { id: group._id }
})
};
}
61 changes: 41 additions & 20 deletions server/controllers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const userModel = require('../models/user.js');
const interfaceModel = require('../models/interface.js');
const interfaceColModel = require('../models/interfaceCol.js');
const interfaceCaseModel = require('../models/interfaceCase.js');
const _ = require('underscore')

const rolename = {
owner: '组长',
Expand Down Expand Up @@ -400,7 +401,7 @@ class groupController extends baseController {
async list(ctx) {
var groupInst = yapi.getInst(groupModel);
let projectInst = yapi.getInst(projectModel);
let result = await groupInst.list();
let result = await groupInst.getAuthList(this.getUid());

let privateGroup = await groupInst.getByPrivateUid(this.getUid());
let newResult = [];
Expand All @@ -415,28 +416,48 @@ class groupController extends baseController {
});
}

if (result && result.length > 0) {
for (let i = 0; i < result.length; i++) {
if(result && result.length > 0 ){
for (let i = 0; i < result.length; i++){
result[i] = result[i].toObject();
result[i].role = await this.getProjectRole(result[i]._id, 'group');
if (result[i].role !== 'member') {
newResult.unshift(result[i]);
} else {
let publicCount = await projectInst.countWithPublic(result[i]._id);
if (publicCount > 0) {
newResult.push(result[i]);
} else {
let projectCountWithAuth = await projectInst.getProjectWithAuth(
result[i]._id,
this.getUid()
);
if (projectCountWithAuth > 0) {
newResult.push(result[i]);
}
}
}
newResult.unshift(result[i])
}
}

const groupIds = newResult.map(item=> item._id);

let groupByProject = await projectInst.getAuthList(this.getUid());
if(groupByProject && groupByProject.length > 0){
groupByProject.forEach( _data=>{
if(!_.find(groupIds, id=> id === _data.group_id)){
groupIds.push(_data.group_id)
}
})
}

newResult = await groupInst.findByGroups(groupIds)

// if (result && result.length > 0) {
// for (let i = 0; i < result.length; i++) {
// result[i] = result[i].toObject();
// result[i].role = await this.getProjectRole(result[i]._id, 'group');
// if (result[i].role !== 'member') {
// newResult.unshift(result[i]);
// } else {
// let publicCount = await projectInst.countWithPublic(result[i]._id);
// if (publicCount > 0) {
// newResult.push(result[i]);
// } else {
// let projectCountWithAuth = await projectInst.getProjectWithAuth(
// result[i]._id,
// this.getUid()
// );
// if (projectCountWithAuth > 0) {
// newResult.push(result[i]);
// }
// }
// }
// }
// }
if (privateGroup) {
privateGroup = privateGroup.toObject();
privateGroup.group_name = '个人空间';
Expand Down
22 changes: 22 additions & 0 deletions server/models/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ class groupModel extends baseModel {
.exec();
}

getAuthList(uid){
return this.model.find({
$or: [{
'members.uid': uid,
'type': 'public'
}, {
'type': 'public',
uid
}]
}).select(' _id group_desc add_time up_time type uid custom_field1')
.exec();

}

findByGroups(ids = []){
return this.model.find({
_id: {
$in: ids
}
})
}

del(id) {
return this.model.remove({
_id: id
Expand Down
11 changes: 11 additions & 0 deletions server/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ class projectModel extends baseModel {
this.handleEnvNullData = this.handleEnvNullData.bind(this)
}

getAuthList(uid){
return this.model.find({
$or: [{
'members.uid': uid
}, {
uid
}]
}).select('group_id')
.exec();
}

getSchema() {
return {
uid: { type: Number, required: true },
Expand Down

0 comments on commit 6dab9fa

Please sign in to comment.