Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
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
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
beb6bbdb
Commit
beb6bbdb
authored
Nov 15, 2022
by
Future
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
去除非必要代码,提升性能
parent
af321b09
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
154 deletions
+42
-154
core/src/main/java/com/wecloud/im/action/NormalChatAction.java
+4
-8
core/src/main/java/com/wecloud/im/ws/sender/ChannelSender.java
+1
-2
core/src/main/resources/ehcache.xml
+37
-0
framework/src/main/java/io/geekidea/springbootplus/framework/common/api/ApiResult.java
+0
-22
framework/src/main/java/io/geekidea/springbootplus/framework/config/il8n/I18nMessageUtil.java
+0
-67
framework/src/main/java/io/geekidea/springbootplus/framework/config/il8n/LanguageEnum.java
+0
-55
No files found.
core/src/main/java/com/wecloud/im/action/NormalChatAction.java
View file @
beb6bbdb
...
...
@@ -179,8 +179,7 @@ public class NormalChatAction {
imConversationMembersService
.
updateBatchById
(
tempMemberToUpdate
);
}
}
// final Boolean isPush = ehcacheService.getIsPush("push" + conversation.getId());
final
Boolean
isPush
=
Boolean
.
FALSE
;
final
Boolean
isPush
=
ehcacheService
.
getIsPush
(
"push"
+
conversation
.
getId
());
// 多线程处理消息下发
long
time5
=
System
.
currentTimeMillis
();
for
(
ImConversationMembers
member
:
membersList
)
{
...
...
@@ -205,7 +204,7 @@ public class NormalChatAction {
long
time1
=
System
.
currentTimeMillis
();
sendMsgForOnline
(
member
.
getFkClientId
(),
imMessageOnlineSend
);
log
.
info
(
"会话id{} 在线发消息耗时 {}
"
,
imMessageOnlineSend
.
getConversationId
(),
System
.
currentTimeMillis
()-
time1
);
log
.
info
(
"会话id{} 在线发消息耗时 {}
isPush {}"
,
imMessageOnlineSend
.
getConversationId
(),
System
.
currentTimeMillis
()-
time1
,
isPush
);
if
(
isPush
&&
!
member
.
getDoNotDisturb
())
{
long
time2
=
System
.
currentTimeMillis
();
try
{
...
...
@@ -229,15 +228,12 @@ public class NormalChatAction {
*/
private
Boolean
sendMsgForOnline
(
Long
receiverClientId
,
ImMessageOnlineSend
imMessageOnlineSend
)
{
// 封装要推给接收方的消息
long
time1
=
System
.
currentTimeMillis
();
WsResponse
<
ImMessageOnlineSend
>
responseModel
=
new
WsResponse
<>();
responseModel
.
setCmd
(
WsResponseCmdEnum
.
ONLINE_MSG
.
getCmdCode
());
ApiResult
<
Boolean
>
result
=
ApiResult
.
result
(
ApiCode
.
SUCCESS
);
responseModel
.
setCode
(
result
.
getCode
());
responseModel
.
setMsg
(
result
.
getMessage
());
responseModel
.
setCode
(
200
);
responseModel
.
setMsg
(
null
);
responseModel
.
setData
(
imMessageOnlineSend
);
responseModel
.
setReqId
(
null
);
log
.
info
(
"构造在线消息耗时 {}"
,
System
.
currentTimeMillis
()
-
time1
);
return
channelSender
.
sendMsg
(
responseModel
,
receiverClientId
);
}
...
...
core/src/main/java/com/wecloud/im/ws/sender/ChannelSender.java
View file @
beb6bbdb
...
...
@@ -133,10 +133,9 @@ public class ChannelSender {
*/
public
Boolean
sendMsg
(
WsResponse
responseModel
,
Long
toClientId
)
{
long
time1
=
System
.
currentTimeMillis
();
String
msgJson
=
JsonUtils
.
encodeJson
(
responseModel
);
List
<
ClientChannelInfo
>
channelInfos
=
userStateCacheManager
.
findOnlineInfosByClientId
(
toClientId
);
log
.
info
(
"获取在线用户耗时 {} 内容 {}"
,
System
.
currentTimeMillis
()
-
time1
,
JSON
.
toJSONString
(
channelInfos
));
//
log.info("获取在线用户耗时 {} 内容 {}", System.currentTimeMillis() - time1, JSON.toJSONString(channelInfos));
if
(
CollectionUtils
.
isEmpty
(
channelInfos
))
{
return
false
;
...
...
core/src/main/resources/ehcache.xml
0 → 100644
View file @
beb6bbdb
<ehcache
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"../config/ehcache.xsd"
>
<diskStore
path=
"java.io.tmpdir"
/>
<defaultCache
maxElementsInMemory=
"10000"
eternal=
"false"
timeToIdleSeconds=
"120"
timeToLiveSeconds=
"120"
maxElementsOnDisk=
"10000000"
diskExpiryThreadIntervalSeconds=
"120"
memoryStoreEvictionPolicy=
"LRU"
>
<persistence
strategy=
"localTempSwap"
/>
</defaultCache>
<cache
name=
"business"
maxElementsInMemory=
"100000"
eternal=
"false"
timeToIdleSeconds=
"86400"
timeToLiveSeconds=
"86400"
maxElementsOnDisk=
"10000000"
diskExpiryThreadIntervalSeconds=
"120"
memoryStoreEvictionPolicy=
"LRU"
>
<persistence
strategy=
"localTempSwap"
/>
</cache>
<cache
name=
"push"
maxElementsInMemory=
"10000"
eternal=
"false"
timeToIdleSeconds=
"180"
timeToLiveSeconds=
"180"
maxElementsOnDisk=
"10000000"
diskExpiryThreadIntervalSeconds=
"120"
memoryStoreEvictionPolicy=
"LRU"
>
<persistence
strategy=
"localTempSwap"
/>
</cache>
</ehcache>
framework/src/main/java/io/geekidea/springbootplus/framework/common/api/ApiResult.java
View file @
beb6bbdb
...
...
@@ -16,14 +16,11 @@
package
io
.
geekidea
.
springbootplus
.
framework
.
common
.
api
;
import
io.geekidea.springbootplus.framework.config.il8n.I18nMessageUtil
;
import
io.geekidea.springbootplus.framework.config.il8n.LanguageEnum
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.io.IOException
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -85,29 +82,10 @@ public class ApiResult<T> implements Serializable {
public
static
<
T
>
ApiResult
<
T
>
result
(
ApiCode
apiCode
,
String
message
,
T
data
)
{
// boolean success = false;
// if (apiCode.getCode() == ApiCode.SUCCESS.getCode()) {
// success = true;
// }
// 多语言国际化,根据http上下文, 取得heard中的language语言属性,实现不用在业务代码中传递语言字段
// HttpServletRequest request = HttpServletRequestUtil.getRequest();
// String language = request.getHeader("language");
String
success
=
"SUCCESS"
;
try
{
message
=
I18nMessageUtil
.
getMessage
(
LanguageEnum
.
getLanguageType
(
null
),
apiCode
.
getMessage
(),
success
);
}
catch
(
IOException
e
)
{
message
=
success
;
}
return
(
ApiResult
<
T
>)
ApiResult
.
builder
()
.
code
(
apiCode
.
getCode
())
.
message
(
message
)
.
data
(
data
)
// .success(success)
// .time(new Date())
.
build
();
}
...
...
framework/src/main/java/io/geekidea/springbootplus/framework/config/il8n/I18nMessageUtil.java
deleted
100644 → 0
View file @
af321b09
package
io
.
geekidea
.
springbootplus
.
framework
.
config
.
il8n
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.context.support.MessageSourceAccessor
;
import
org.springframework.context.support.ReloadableResourceBundleMessageSource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.support.PathMatchingResourcePatternResolver
;
import
org.springframework.core.io.support.ResourcePatternResolver
;
import
java.io.IOException
;
/**
* 多语言国际化消息工具类
*/
public
class
I18nMessageUtil
{
// 根目录
private
static
final
String
PATH_PARENT
=
"classpath:static/i18n/messages_"
;
// 后缀
private
static
final
String
SUFFIX
=
".properties"
;
// 分解器
private
static
final
ResourcePatternResolver
RESOURCE_PATTERN_RESOLVER
=
new
PathMatchingResourcePatternResolver
();
// 存取器
private
static
MessageSourceAccessor
accessor
;
private
I18nMessageUtil
()
{
}
/**
* 初始化资源文件的存储器
* 加载指定语言配置文件
*
* @param language 语言类型(文件名即为语言类型,eg: en_us 表明使用 美式英文 语言配置)
*/
private
static
void
initMessageSourceAccessor
(
String
language
)
throws
IOException
{
/*
* 获取配置文件名
*/
Resource
resource
=
RESOURCE_PATTERN_RESOLVER
.
getResource
(
PATH_PARENT
+
language
+
SUFFIX
);
String
fileName
=
resource
.
getURL
().
toString
();
int
lastIndex
=
fileName
.
lastIndexOf
(
"."
);
String
baseName
=
fileName
.
substring
(
0
,
lastIndex
);
/*
* 读取配置文件
*/
ReloadableResourceBundleMessageSource
reloadableResourceBundleMessageSource
=
new
ReloadableResourceBundleMessageSource
();
reloadableResourceBundleMessageSource
.
setBasename
(
baseName
);
reloadableResourceBundleMessageSource
.
setCacheSeconds
(
5
);
reloadableResourceBundleMessageSource
.
setDefaultEncoding
(
"UTF-8"
);
accessor
=
new
MessageSourceAccessor
(
reloadableResourceBundleMessageSource
);
}
/**
* 获取一条语言配置信息
*
* @param language 语言类型,zh_CN: 简体中文, en_US: 英文
* @param message 配置信息属性名,eg: api.response.code.user.signUp
* @param defaultMessage 默认信息,当无法从配置文件中读取到对应的配置信息时返回该信息
* @return
* @throws IOException
*/
public
static
String
getMessage
(
String
language
,
String
message
,
String
defaultMessage
)
throws
IOException
{
initMessageSourceAccessor
(
language
);
return
accessor
.
getMessage
(
message
,
defaultMessage
,
LocaleContextHolder
.
getLocale
());
}
}
framework/src/main/java/io/geekidea/springbootplus/framework/config/il8n/LanguageEnum.java
deleted
100644 → 0
View file @
af321b09
package
io
.
geekidea
.
springbootplus
.
framework
.
config
.
il8n
;
import
lombok.Getter
;
import
lombok.ToString
;
import
org.springframework.util.StringUtils
;
/**
* 语言枚举类
*/
@Getter
@ToString
public
enum
LanguageEnum
{
/**
* 美式英文
*/
LANGUAGE_EN_US
(
"en_US"
),
// /**
// * 柬埔寨 高棉语
// */
// LANGUAGE_KH("kh"),
/**
* 简体中文
*/
LANGUAGE_ZH_CN
(
"zh_CN"
);
private
final
String
language
;
LanguageEnum
(
String
language
)
{
this
.
language
=
language
;
}
/**
* 获取指定语言类型(如果没有对应的语言类型,则返回中文)
*
* @param language 语言类型
* @return
*/
public
static
String
getLanguageType
(
String
language
)
{
// 设置默认为中文
if
(
StringUtils
.
isEmpty
(
language
))
{
return
LANGUAGE_ZH_CN
.
language
;
}
for
(
LanguageEnum
languageEnum
:
LanguageEnum
.
values
())
{
if
(
languageEnum
.
language
.
equalsIgnoreCase
(
language
))
{
return
languageEnum
.
language
;
}
}
return
LANGUAGE_ZH_CN
.
language
;
}
}
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