缓存优化,执行器查询展示优化
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package com.zyplayer.doc.data.utils;
|
||||
|
||||
public class CachePrefix {
|
||||
public static final String WIKI_LOCK_PAGE = "WIKI_LOCK_PAGE_";
|
||||
public static final String DB_EDITOR_DATA_CACHE = "DB_EDITOR_DATA_CACHE_";
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.zyplayer.doc.data.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
@@ -8,12 +10,13 @@ import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 缓存工具类
|
||||
* 轻量缓存工具类
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年05月25日
|
||||
*/
|
||||
public class CacheUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(CacheUtil.class);
|
||||
|
||||
// 定期清除过期的key
|
||||
static {
|
||||
@@ -22,67 +25,99 @@ public class CacheUtil {
|
||||
@Override
|
||||
public void run() {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
for (Map.Entry<String, CacheTime> entry : cacheTimeMap.entrySet()) {
|
||||
CacheTime cacheTime = entry.getValue();
|
||||
if (currentTimeMillis - cacheTime.getLastVisitTime() < (cacheTime.getSecond() * 1000)) {
|
||||
for (String key : cacheDataMap.keySet()) {
|
||||
CacheData cacheData = cacheDataMap.get(key);
|
||||
if (cacheData == null || currentTimeMillis - cacheData.getLastVisitTime() < (cacheData.getSeconds() * 1000)) {
|
||||
continue;
|
||||
}
|
||||
cacheMap.remove(entry.getKey());
|
||||
cacheDataMap.remove(key);
|
||||
logger.info("缓存过期,清理缓存:{}", key);
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}, 0, 5000);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
CacheUtil.put("xx", "xx", 6);
|
||||
Thread.sleep(4000);
|
||||
CacheUtil.get("xx");
|
||||
System.out.println(cacheDataMap.get("xx").getLastVisitTime());
|
||||
Thread.sleep(7000);
|
||||
CacheUtil.get("xx");
|
||||
System.out.println(cacheDataMap.get("xx").getLastVisitTime());
|
||||
Thread.sleep(99000);
|
||||
}
|
||||
|
||||
// 现在是内存缓存,不支持分布式部署,后期考虑放到redis,但感觉也没必要。。
|
||||
private static Map<String, Object> cacheMap = new ConcurrentHashMap<>();
|
||||
private static Map<String, CacheTime> cacheTimeMap = new ConcurrentHashMap<>();
|
||||
private static Map<String, CacheData> cacheDataMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 放入缓存,默认12小时,按最后一次访问的12小时
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public static void put(String key, Object value) {
|
||||
put(key, value, (long) (60 * 60 * 12));
|
||||
put(key, value, 60 * 60 * 12);
|
||||
}
|
||||
|
||||
public static void put(String key, Object value, Long second) {
|
||||
/**
|
||||
* 放入缓存,有访问则继续有效
|
||||
* @param key
|
||||
* @param value
|
||||
* @param seconds 缓存时长 秒
|
||||
*/
|
||||
public static void put(String key, Object value, long seconds) {
|
||||
if (StringUtils.isBlank(key) || value == null) {
|
||||
return;
|
||||
}
|
||||
cacheMap.put(key, value);
|
||||
cacheTimeMap.put(key, new CacheTime(second));
|
||||
cacheDataMap.put(key, new CacheData(seconds, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @param key
|
||||
*/
|
||||
public static void remove(String key) {
|
||||
if (StringUtils.isBlank(key)) {
|
||||
return;
|
||||
}
|
||||
cacheMap.remove(key);
|
||||
cacheTimeMap.remove(key);
|
||||
cacheDataMap.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存
|
||||
* @param key
|
||||
*/
|
||||
public static <T> T get(String key) {
|
||||
if (StringUtils.isBlank(key)) {
|
||||
return null;
|
||||
}
|
||||
CacheTime cacheTime = cacheTimeMap.get(key);
|
||||
if (cacheTime != null) {
|
||||
cacheTime.setLastVisitTime(System.currentTimeMillis());
|
||||
cacheTimeMap.put(key, cacheTime);
|
||||
CacheData cacheData = cacheDataMap.get(key);
|
||||
if (cacheData != null) {
|
||||
cacheData.setLastVisitTime(System.currentTimeMillis());
|
||||
return (T) cacheData.getData();
|
||||
}
|
||||
return (T) cacheMap.get(key);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class CacheTime {
|
||||
private Long second;
|
||||
private static class CacheData {
|
||||
/**缓存时长 秒*/
|
||||
private Long seconds;
|
||||
private Long lastVisitTime;
|
||||
private Object data;
|
||||
|
||||
public CacheTime(Long second) {
|
||||
this.second = second;
|
||||
public CacheData(long seconds, Object data) {
|
||||
this.data = data;
|
||||
this.seconds = seconds;
|
||||
this.lastVisitTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Long getSecond() {
|
||||
return second;
|
||||
public Long getSeconds() {
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public void setSecond(Long second) {
|
||||
this.second = second;
|
||||
public void setSeconds(Long seconds) {
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
public Long getLastVisitTime() {
|
||||
@@ -92,5 +127,13 @@ public class CacheUtil {
|
||||
public void setLastVisitTime(Long lastVisitTime) {
|
||||
this.lastVisitTime = lastVisitTime;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.zyplayer.doc.data.repository.manage.entity.UserAuth;
|
||||
import com.zyplayer.doc.data.repository.support.consts.DocAuthConst;
|
||||
import com.zyplayer.doc.data.service.manage.DbDatasourceService;
|
||||
import com.zyplayer.doc.data.service.manage.UserAuthService;
|
||||
import com.zyplayer.doc.data.utils.CachePrefix;
|
||||
import com.zyplayer.doc.data.utils.CacheUtil;
|
||||
import com.zyplayer.doc.db.controller.vo.DatabaseExportVo;
|
||||
import com.zyplayer.doc.db.controller.vo.TableColumnVo;
|
||||
import com.zyplayer.doc.db.controller.vo.TableColumnVo.TableInfoVo;
|
||||
@@ -97,6 +99,11 @@ public class DatabaseDocController {
|
||||
&& !DocUserUtil.haveCustomAuth(DbAuthType.VIEW.getName(), DocAuthConst.DB + sourceId)) {
|
||||
return DocDbResponseJson.ok();
|
||||
}
|
||||
String cacheKey = CachePrefix.DB_EDITOR_DATA_CACHE + sourceId;
|
||||
Object resultObj = CacheUtil.get(cacheKey);
|
||||
if (resultObj != null) {
|
||||
return DocDbResponseJson.ok(resultObj);
|
||||
}
|
||||
BaseMapper baseMapper = this.getBaseMapper(sourceId);
|
||||
DatabaseFactoryBean databaseFactoryBean = databaseRegistrationBean.getFactoryById(sourceId);
|
||||
List<DatabaseInfoDto> dbNameDtoList = baseMapper.getDatabaseList();
|
||||
@@ -121,6 +128,8 @@ public class DatabaseDocController {
|
||||
dbResultMap.put("db", dbNameDtoList);
|
||||
dbResultMap.put("table", dbTableMap);
|
||||
dbResultMap.put("column", tableColumnsMap);
|
||||
// 缓存10分钟,如果10分钟内库里面增删改了表或字段,则提示不出来
|
||||
CacheUtil.put(cacheKey, dbResultMap, 6000);
|
||||
return DocDbResponseJson.ok(dbResultMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.zyplayer.doc.db.framework.db.support;
|
||||
|
||||
/**
|
||||
* 动态分库使用
|
||||
*/
|
||||
public class DBInfoHolder {
|
||||
private static final ThreadLocal<String> DB_INFO_NOW = new ThreadLocal<String>();
|
||||
|
||||
public static void setDbInfoNow(String dbInfo) {
|
||||
DB_INFO_NOW.set(dbInfo);
|
||||
}
|
||||
|
||||
public static String getDbInfoNow() {
|
||||
return DB_INFO_NOW.get();
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.zyplayer.doc.db.framework.db.support;
|
||||
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
/**
|
||||
* 动态切换数据源
|
||||
*/
|
||||
public class ErpRoutingDataSource extends AbstractRoutingDataSource {
|
||||
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DBInfoHolder.getDbInfoNow();
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
|
||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var a,i,f,l=0,s=[];l<t.length;l++)i=t[l],o[i]&&s.push(o[i][0]),o[i]=0;for(a in c)Object.prototype.hasOwnProperty.call(c,a)&&(e[a]=c[a]);for(r&&r(t,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=n(n.s=u[l]);return f};var t={},o={2:0};n.e=function(e){function r(){a.onerror=a.onload=null,clearTimeout(i);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var u=document.getElementsByTagName("head")[0],a=document.createElement("script");a.type="text/javascript",a.charset="utf-8",a.async=!0,a.timeout=12e4,n.nc&&a.setAttribute("nonce",n.nc),a.src=n.p+""+e+".js?"+{0:"49668c3fbed15a679eda",1:"0a0403eb1820498dc9bc"}[e];var i=setTimeout(r,12e4);return a.onerror=a.onload=r,u.appendChild(a),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
||||
//# sourceMappingURL=doc-db-manifest.js.map?4cab9b90fde0f8edb725
|
||||
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,a){for(var u,i,f,l=0,s=[];l<t.length;l++)i=t[l],o[i]&&s.push(o[i][0]),o[i]=0;for(u in c)Object.prototype.hasOwnProperty.call(c,u)&&(e[u]=c[u]);for(r&&r(t,c,a);s.length;)s.shift()();if(a)for(l=0;l<a.length;l++)f=n(n.s=a[l]);return f};var t={},o={2:0};n.e=function(e){function r(){u.onerror=u.onload=null,clearTimeout(i);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var a=document.getElementsByTagName("head")[0],u=document.createElement("script");u.type="text/javascript",u.charset="utf-8",u.async=!0,u.timeout=12e4,n.nc&&u.setAttribute("nonce",n.nc),u.src=n.p+""+e+".js?"+{0:"ae1e13bde53c50facad6",1:"0a0403eb1820498dc9bc"}[e];var i=setTimeout(r,12e4);return u.onerror=u.onload=r,a.appendChild(u),c},n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n.oe=function(e){throw console.error(e),e}}([]);
|
||||
//# sourceMappingURL=doc-db-manifest.js.map?c1844f50fc431da7b290
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="text/javascript" src="doc-db-manifest.js?4cab9b90fde0f8edb725"></script><script type="text/javascript" src="doc-db-vendor.js?0a0403eb1820498dc9bc"></script><script type="text/javascript" src="doc-db-index.js?49668c3fbed15a679eda"></script></body>
|
||||
<script type="text/javascript" src="doc-db-manifest.js?c1844f50fc431da7b290"></script><script type="text/javascript" src="doc-db-vendor.js?0a0403eb1820498dc9bc"></script><script type="text/javascript" src="doc-db-index.js?ae1e13bde53c50facad6"></script></body>
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ZyplayerProxyFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,7 +137,7 @@ public class ZyplayerProxyFilter implements Filter {
|
||||
httpRequest.cookie(httpCookieList.toArray(new HttpCookie[]{}));
|
||||
}
|
||||
String resultStr = httpRequest.execute().body();
|
||||
if (proxyUrl.indexOf(Consts.V2_API_DOCS) >= 0) {
|
||||
if (proxyUrl.contains(Consts.V2_API_DOCS)) {
|
||||
// "basePath":"/" 替换成 "basePath":"/zyplayer-doc-manage/zyplayer-proxy/2/",使其走代理接口
|
||||
ServletContext servletContext = httpServletRequest.getServletContext();
|
||||
Object ctx = servletContext.getAttribute("ctx");
|
||||
|
||||
@@ -29,7 +29,11 @@
|
||||
<el-table-column width="60px" v-if="executeResultCols.length > 0">
|
||||
<template slot-scope="scope">{{scope.row._index}}</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-for="item in executeResultCols" :prop="item.prop" :label="item.prop"></el-table-column>
|
||||
<el-table-column v-for="item in executeResultCols" :prop="item.prop" :label="item.prop">
|
||||
<template slot-scope="scope">
|
||||
<el-input :value="scope.row[item.prop]" :readonly="true"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</el-card>
|
||||
@@ -257,9 +261,9 @@
|
||||
if (lineStr.endsWith(app.editorDbInfo[i].dbName + ".")) {
|
||||
var tableInfo = app.editorDbTableInfo[app.editorDbInfo[i].dbName];
|
||||
if (!!tableInfo) {
|
||||
for (var i = 0; i < tableInfo.length; i++) {
|
||||
var caption = (!!tableInfo[i].tableComment) ? tableInfo[i].tableName + "-" + tableInfo[i].tableComment : tableInfo[i].tableName;
|
||||
callbackArr.push({caption: caption, snippet: tableInfo[i].tableName, meta: "table", type: "snippet", score : 1000});
|
||||
for (var j = 0; j < tableInfo.length; j++) {
|
||||
var caption = (!!tableInfo[j].tableComment) ? tableInfo[j].tableName + "-" + tableInfo[j].tableComment : tableInfo[j].tableName;
|
||||
callbackArr.push({caption: caption, snippet: tableInfo[j].tableName, meta: "table", type: "snippet", score : 1000});
|
||||
}
|
||||
isFound = true;
|
||||
}
|
||||
@@ -309,9 +313,9 @@
|
||||
}
|
||||
var columnInfo = app.editorColumnInfo[tableInfo[i].tableName];
|
||||
if (!!columnInfo) {
|
||||
for (var i = 0; i < columnInfo.length; i++) {
|
||||
var caption = (!!columnInfo[i].description) ? columnInfo[i].name + "-" + columnInfo[i].description : columnInfo[i].name;
|
||||
callbackArr.push({caption: caption, snippet: columnInfo[i].name, meta: "column", type: "snippet", score : 1000});
|
||||
for (var j = 0; j < columnInfo.length; j++) {
|
||||
var caption = (!!columnInfo[j].description) ? columnInfo[j].name + "-" + columnInfo[j].description : columnInfo[j].name;
|
||||
callbackArr.push({caption: caption, snippet: columnInfo[j].name, meta: "column", type: "snippet", score : 1000});
|
||||
}
|
||||
isFound = true;
|
||||
}
|
||||
@@ -336,6 +340,11 @@
|
||||
.data-executor-vue .el-table td, .el-table th{
|
||||
padding: 6px 0;
|
||||
}
|
||||
.data-executor-vue .el-input__inner{
|
||||
height: 25px;
|
||||
line-height: 25px;
|
||||
padding: 0 5px;
|
||||
}
|
||||
.data-executor-vue-out .el-tabs__nav-scroll{
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ import com.zyplayer.doc.data.service.elasticsearch.entity.EsWikiPage;
|
||||
import com.zyplayer.doc.data.service.elasticsearch.service.EsWikiPageService;
|
||||
import com.zyplayer.doc.data.service.elasticsearch.support.EsPage;
|
||||
import com.zyplayer.doc.data.service.manage.*;
|
||||
import com.zyplayer.doc.data.utils.CachePrefix;
|
||||
import com.zyplayer.doc.data.utils.CacheUtil;
|
||||
import com.zyplayer.doc.wiki.controller.vo.WikiPageContentVo;
|
||||
import com.zyplayer.doc.wiki.controller.vo.WikiPageVo;
|
||||
import com.zyplayer.doc.wiki.framework.consts.SpaceType;
|
||||
import com.zyplayer.doc.wiki.framework.consts.WikiAuthType;
|
||||
import com.zyplayer.doc.wiki.framework.consts.WikiCachePrefix;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dozer.Mapper;
|
||||
@@ -287,7 +287,7 @@ public class WikiPageController {
|
||||
|
||||
@PostMapping("/unlock")
|
||||
public ResponseJson<Object> unlock(Long pageId) {
|
||||
String lockKey = WikiCachePrefix.WIKI_LOCK_PAGE + pageId;
|
||||
String lockKey = CachePrefix.WIKI_LOCK_PAGE + pageId;
|
||||
DocUserDetails pageLockUser = CacheUtil.get(lockKey);
|
||||
if (pageLockUser != null) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
@@ -301,7 +301,7 @@ public class WikiPageController {
|
||||
@PostMapping("/lock")
|
||||
public ResponseJson<Object> editLock(Long pageId) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
String lockKey = WikiCachePrefix.WIKI_LOCK_PAGE + pageId;
|
||||
String lockKey = CachePrefix.WIKI_LOCK_PAGE + pageId;
|
||||
DocUserDetails pageLockUser = CacheUtil.get(lockKey);
|
||||
if (pageLockUser != null) {
|
||||
if (!Objects.equals(pageLockUser.getUserId(), currentUser.getUserId())) {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.zyplayer.doc.wiki.framework.consts;
|
||||
|
||||
public class WikiCachePrefix {
|
||||
public static final String WIKI_LOCK_PAGE = "WIKI_LOCK_PAGE_";
|
||||
}
|
||||
Reference in New Issue
Block a user