Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(desktop): remove some useless data from vuex #1171

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/database/services/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,8 @@ export default class ConnectionService {
public async delete(id: string): Promise<ConnectionModel | undefined> {
const query: ConnectionEntity | undefined = await this.connectionRepository
.createQueryBuilder('cn')
.select(['cn.id'])
.where('cn.id = :id', { id })
.leftJoinAndSelect('cn.messages', 'msg')
.leftJoinAndSelect('cn.subscriptions', 'sub')
.leftJoinAndSelect('cn.will', 'will')
.getOne()
if (!query) {
Expand Down
4 changes: 1 addition & 3 deletions src/store/modules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ const app = {
state.maxReconnectTimes = maxReconnectTimes
},
[CHANGE_ACTIVE_CONNECTION](state: App, payload: Client) {
const { id, client, messages } = payload
const { id, client } = payload
if (state.activeConnection[id]) {
// already exists activeConnection
Vue.set(state.activeConnection[id], 'client', client)
Vue.set(state.activeConnection[id], 'messages', messages)
} else {
// new activeConnection
Vue.set(state.activeConnection, id, {
client,
messages,
})
}
},
Expand Down
2 changes: 0 additions & 2 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ declare global {
interface ActiveConnection {
[id: string]: {
client: MqttClient
messages: MessageModel[]
subscriptions?: SubscriptionModel[]
}
}
Expand Down Expand Up @@ -127,7 +126,6 @@ declare global {
interface Client {
readonly id: string
client: Partial<MqttClient>
messages: MessageModel[]
}

interface Message {
Expand Down
1 change: 0 additions & 1 deletion src/views/connections/ConnectionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ export default class ConnectionForm extends Vue {
client: {
connected: false,
},
messages: [],
})
this.$emit('connect')
this.$router.push(`/recent_connections/${res.id}`)
Expand Down
4 changes: 0 additions & 4 deletions src/views/connections/ConnectionsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ export default class ConnectionsDetail extends Vue {
this.changeActiveConnection({
id: this.curConnectionId,
client: this.client,
messages: [],
})
if (this.record.id) {
const { messageService } = useServices()
Expand Down Expand Up @@ -912,7 +911,6 @@ export default class ConnectionsDetail extends Vue {
this.changeActiveConnection({
id: this.curConnectionId,
client: this.client,
messages: this.record.messages,
})
this.$notify({
title: this.$tc('connections.disconnected'),
Expand All @@ -936,7 +934,6 @@ export default class ConnectionsDetail extends Vue {
this.changeActiveConnection({
id: this.curConnectionId,
client: this.client,
messages: this.record.messages,
})
this.$notify({
title: this.$tc('connections.connected'),
Expand Down Expand Up @@ -1520,7 +1517,6 @@ export default class ConnectionsDetail extends Vue {
this.changeActiveConnection({
id: connectionID,
client,
messages: this.messages,
})
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/views/connections/ConnectionsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ import time from '@/utils/time'
},
})
export default class ConnectionsList extends Vue {
@Prop({ required: true }) public ConnectionModelData!: ConnectionModel[] | []
@Prop({ required: true }) public connectionCount!: number

@Action('UNREAD_MESSAGE_COUNT_INCREMENT') private unreadMessageIncrement!: (payload: UnreadMessage) => void
@Action('SET_CONNECTIONS_TREE') private setConnectionsTree!: (payload: ConnectionTreeState) => void
Expand Down Expand Up @@ -192,9 +192,9 @@ export default class ConnectionsList extends Vue {
this.selectedCollection = null
}
}
@Watch('ConnectionModelData')
private handleConnectionModelDataChange(val: ConnectionModel[] | [], oldVal: ConnectionModel[] | []) {
this.loadData(val.length === 1 && oldVal.length === 0)
@Watch('connectionCount')
private handleConnectionCountChange(val: number, oldVal: number) {
this.loadData(val === 1 && oldVal === 0)
}
@Watch('$route.params.id')
private handleConnectionIdChanged(id: string) {
Expand Down
12 changes: 4 additions & 8 deletions src/views/connections/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="connections">
<div class="left-list">
<ConnectionsList :ConnectionModelData="records" @delete="onDelete" @reload="loadData(true, false)" />
<ConnectionsList :connectionCount="connectionCount" @delete="onDelete" @reload="loadData(true, false)" />
</div>
<div class="connections-view">
<template v-if="isLoadingData">
Expand Down Expand Up @@ -49,7 +49,7 @@ import { getDefaultRecord } from '@/utils/mqttUtils'
export default class Connections extends Vue {
private isEmpty: boolean = false
private isLoadingData: boolean = false
private records: ConnectionModel[] = []
private connectionCount: number = 0
private currentConnection: ConnectionModel = { ...getDefaultRecord() }

@Watch('$route.params.id')
Expand Down Expand Up @@ -85,10 +85,6 @@ export default class Connections extends Vue {
return this.$route.params.id
}

get vueForm(): VueForm {
return this.$refs.form as VueForm
}

private async loadDetail(id: string): Promise<void> {
const { connectionService } = useServices()
const res: ConnectionModel | undefined = await connectionService.get(id)
Expand All @@ -102,8 +98,8 @@ export default class Connections extends Vue {
this.isLoadingData = true
}
const { connectionService } = useServices()
const connections: ConnectionModel[] | [] = (await connectionService.cascadeGetAll()) ?? []
this.records = connections
const connections: ConnectionModel[] | [] = (await connectionService.getAll()) ?? []
this.connectionCount = connections.length
this.isLoadingData = false
if (connections.length && loadLatest) {
const leatestId = await connectionService.getLeatestId()
Expand Down