优化查询时间
This commit is contained in:
parent
cdeabd46e4
commit
449d7122af
|
|
@ -114,6 +114,8 @@ module.exports = class extends Base {
|
|||
|
||||
// 获取分类信息
|
||||
async tagsAction() {
|
||||
/*
|
||||
// 这里的查询太慢,使用原始的sql查询先替代
|
||||
let param = this.get();
|
||||
let tags = await this.model('tags').where({ userId: this.ctx.state.user.id }).order('sort ASC, lastUse DESC').select();
|
||||
// 这个分类包含的书签与备忘录的个数
|
||||
|
|
@ -125,6 +127,10 @@ module.exports = class extends Base {
|
|||
tag.noteCount = await this.model('notes').where({ tagId: tag.id }).count();
|
||||
}
|
||||
}
|
||||
*/
|
||||
let sql = "SELECT t.*, tb.bookmarkCount, tg.noteCount FROM `tags` as t LEFT OUTER JOIN ( SELECT `tagId`, COUNT(tagId) as bookmarkCount FROM bookmarks GROUP BY tagId ) tb ON t.id = tb.tagId LEFT OUTER JOIN ( SELECT `tagId`, COUNT(tagId) as noteCount FROM notes GROUP BY tagId ) tg ON t.id = tg.tagId where t.userId = " + this.ctx.state.user.id;
|
||||
let tags = await this.model('tags').query(sql);
|
||||
|
||||
this.json({ code: 0, data: tags, msg: '' });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +1,25 @@
|
|||
var app = angular.module('bookmarkApp', ['ui.router', 'ngCookies', 'infinite-scroll', 'angular-sortable-view', 'ngDialog']);
|
||||
|
||||
axios.defaults.baseURL = '/api/';
|
||||
axios.defaults.headers.common['Authorization'] = localStorage.getItem("authorization");
|
||||
|
||||
function get(url, params) {
|
||||
params = params || {};
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(url, {
|
||||
params: params || {}
|
||||
}).then(res => {
|
||||
resolve(res);
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
axios.get(url, { params }).then(res => resolve(res)).catch(err => reject(err))
|
||||
});
|
||||
}
|
||||
|
||||
function post(url, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(url, params || {})
|
||||
.then(res => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
axios.post(url, params || {}).then(res => resolve(res)).catch(err => reject(err))
|
||||
});
|
||||
}
|
||||
|
||||
axios.interceptors.request.use(config => {
|
||||
config.headers.Authorization = localStorage.getItem("authorization");
|
||||
return config;
|
||||
})
|
||||
|
||||
// 添加响应拦截器
|
||||
axios.interceptors.response.use(function (response) {
|
||||
let reply = response.data;
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
|||
var url = $scope.quickUrl[key];
|
||||
if (url) {
|
||||
$window.open(url, '_blank');
|
||||
let data = await post('bookmarShortcutk', { url });
|
||||
let data = await post('bookmarShortcut', { url });
|
||||
if (!data) {
|
||||
toastr.info('网址:' + url + "还没添加到你的书签系统,请添加!", "警告");
|
||||
pubSubService.publish('TagCtr.storeBookmark', { url });
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
duration: 1000,
|
||||
});
|
||||
addBookmarkId = -1;
|
||||
}, 1000);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changeCurrentPage = function (currentPage) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue