Commit dc8f7637 by Sixong.Zhu

性能优化,缓存处理

parent 5b0e1790
......@@ -117,6 +117,8 @@ interface Reply {
const ReplyModelName = "uniplat_chat_reply";
let cacheReply: Reply[] = [];
@Component({ components: {} })
export default class MsgShortCut extends Vue {
@chatStore.Action(ChatStore.ACTION_SEND_MESSAGE)
......@@ -138,18 +140,21 @@ export default class MsgShortCut extends Vue {
private editingItem: { [key: string]: boolean } = {};
private editingItemContent: { [key: string]: string } = {};
async mounted() {
await this.getReplyList();
mounted() {
this.getReplyList();
}
private async getReplyList() {
this.replyList = await this.sdk
if (cacheReply && cacheReply.length) {
return (this.replyList = cacheReply);
}
cacheReply = this.replyList = await this.sdk
.domainService("uniplat_base", "chat.chat", "reply")
.request("get");
}
@buttonThrottle()
private sendMsg(reply: Reply) {
private async sendMsg(reply: Reply) {
return this._sendMsg({
msgType: MessageType.Text,
msg: JSON.stringify({ text: reply.content, source: this.source }),
......@@ -263,6 +268,7 @@ export default class MsgShortCut extends Vue {
}
}
</script>
<style lang="less" scoped>
.shortcut {
position: relative;
......
......@@ -73,7 +73,7 @@ import {
MESSAGE_FILE_TOO_LARGE,
MESSAGE_IMAGE_TOO_LARGE,
} from "../components/message-item/file-controller";
import { EmojiService } from "../service/emoji";
import { EmojiItem, EmojiService } from "../service/emoji";
import { ChatStore } from "../store/model";
import { formatFileSize } from "../utils";
......@@ -130,7 +130,7 @@ export default class Input extends Vue {
private tip4Image = `发送图片(最大${MAX_IMAGE_SIZE_STRING})`;
private tip4File = `发送文件(最大${MAX_FILE_SIZE_STRING})`;
private emoji: { name: string; emoji_chars: string; code: string }[] = [];
private emoji: EmojiItem[] = [];
@Watch("chatId")
private onChatIdChanged(v: number, old: number) {
......
import { TokenStringGetter } from "../model";
import { invokeGet } from "./request";
export interface EmojiItem {
code: string;
name: string;
emoji_chars: string;
}
export interface EmojiResult {
type: string;
list: EmojiItem[];
}
let cacheEmoji: EmojiResult | null = null;
export class EmojiService {
private static ready = false
private static token: TokenStringGetter
private static beforeReadyCacheAction: Function[] = []
private url = ""
private static ready = false;
private static token: TokenStringGetter;
private static beforeReadyCacheAction: Function[] = [];
private url = "";
public constructor() {
this.url =
......@@ -16,15 +28,14 @@ export class EmojiService {
}
public async getEmoji() {
if (cacheEmoji) {
return Promise.resolve(cacheEmoji);
}
const token = await EmojiService.token();
return invokeGet<{
type: string;
list: {
code: string;
name: string;
emoji_chars: string;
}[];
}>(`${this.url}/v1/emoji/list?type=chat`, token);
return invokeGet<EmojiResult>(
`${this.url}/v1/emoji/list?type=chat`,
token
).then((o) => (cacheEmoji = o));
}
public static onReady(callback: () => void) {
......
......@@ -3,7 +3,6 @@ import { Module } from "vuex";
import { dbController } from "../database";
import {
ChatMember,
MessageType,
ServiceType,
MessageHandled,
RawChatItem,
......@@ -33,7 +32,7 @@ function uniqueMessages(
messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY>
) {
const arr = [...messages];
return unique(arr, function(item, all) {
return unique(arr, function (item, all) {
return all.findIndex((k) => k.id === item.id);
});
}
......@@ -317,7 +316,7 @@ export default {
state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current];
}
},
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function() {
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function () {
const setTimeoutId: { [key: string]: number } = {};
return (
state: ChatStoreState,
......@@ -419,12 +418,6 @@ export default {
items.forEach((i) => (sum += i.unread_msg_count));
state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum;
},
// async [ChatStore.ACTION_JOIN_CHAT](
// { commit },
// chatId: Parameters<ChatStore.ACTION_JOIN_CHAT>[0]
// ) {
// // return await XimService.getInstance().joinChat(chatId)
// },
async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatId == null) return;
......@@ -721,7 +714,7 @@ export default {
}
commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function(item, all) {
unique(newChatMembers, function (item, all) {
return all.findIndex((k) => k.eid === item.eid);
})
);
......@@ -756,9 +749,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk().model(model_name).chat(obj_id, orgId()).startChat();
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.startChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async [ChatStore.ACTION_CHAT_FINISH_RECEPTION]({ getters, dispatch }) {
const currentChat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT];
......@@ -766,9 +761,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk().model(model_name).chat(obj_id, orgId()).finishChat();
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.finishChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async [ChatStore.ACTION_CHAT_USER_EXIT]({ getters, dispatch }) {
const currentChat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT];
......@@ -776,9 +773,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk().model(model_name).chat(obj_id, orgId()).userExitChat();
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.userExitChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async [ChatStore.ACTION_CHAT_CS_EXIT]({ getters, dispatch }) {
const currentChat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT];
......@@ -786,9 +785,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk().model(model_name).chat(obj_id, orgId()).csExitChat();
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.csExitChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async [ChatStore.ACTION_CHAT_ADD_MEMBERS](
{ getters, dispatch },
......@@ -799,12 +800,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk()
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.addMember(uids.map((id) => Number(id)));
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
.addMember(uids.map((id) => Number(id)))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async [ChatStore.ACTION_CHAT_REMOVE_MEMBER](
{ getters, dispatch },
......@@ -815,12 +815,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk()
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.removeMember(uids.map((id) => Number(id)));
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
.removeMember(uids.map((id) => Number(id)))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async [ChatStore.ACTION_CHAT_ADD_CS](
{ getters, dispatch },
......@@ -831,12 +830,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk()
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.addCs(uids.map((id) => Number(id)));
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
.addCs(uids.map((id) => Number(id)))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
async [ChatStore.ACTION_CHAT_REMOVE_CS](
{ getters, dispatch },
......@@ -847,12 +845,11 @@ export default {
const { model_name, obj_id } = currentChat;
if (model_name == null) return;
if (obj_id == null) return;
await sdk()
return await sdk()
.model(model_name)
.chat(obj_id, orgId())
.removeCs(uids.map((id) => Number(id)));
await new Promise((resolve) => setTimeout(resolve, 500));
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
.removeCs(uids.map((id) => Number(id)))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
},
[ChatStore.ACTION_SET_HANDLED](
{ state },
......
......@@ -3,24 +3,34 @@ import Chat from "../xim";
export type ChatInfo = {
[eid: string]: any;
};
const chatInfo: ChatInfo = {};
export const getChatModel = () => chatInfo;
export async function getChatModelInfo(modelName: string, id: string, detailname?: string) {
if (chatInfo[id] != null) {
return {
uniplatId: chatInfo[id].row.UniplatChatId.value,
chat_id: +chatInfo[id].row.UniplatImChatId.value,
uniplat_version: 0,
};
export async function getChatModelInfo(
modelName: string,
id: string | number,
detailname?: string
) {
if (chatInfo[id]) {
return Promise.resolve({
uniplatId: chatInfo[id].row.UniplatChatId.value,
chat_id: +chatInfo[id].row.UniplatImChatId.value,
uniplat_version: 0,
data: chatInfo[id],
});
}
const info = await Chat.getSdk().model(modelName).detail(id, detailname).query();
const info = await Chat.getSdk()
.model(modelName)
.detail(id + "", detailname)
.query();
const data = info;
chatInfo[id] = data;
return {
uniplatId: info.row.UniplatChatId.value,
chat_id: Number(info.row.UniplatImChatId.value),
uniplat_version: 0,
data,
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment