Skip to content

Commit

Permalink
Improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Jun 2, 2022
1 parent 95ecec4 commit 54da54b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 34 deletions.
2 changes: 1 addition & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ configurations {
}

dependencies {
implementation("me.shedaniel:linkie-core:1.0.101")
implementation("me.shedaniel:linkie-core:1.0.102")
implementation("io.ktor:ktor-server-cors:2.0.1")
implementation("io.ktor:ktor-server-content-negotiation:2.0.1")
implementation("io.ktor:ktor-server-status-pages:2.0.1")
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ export default defineComponent({
body {
@apply bg-base-200
}
.select {
outline: 0 !important;
border: 0 !important;
}
</style>
4 changes: 3 additions & 1 deletion frontend/src/app/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export function reqNamespaces<T = any>(): Promise<AxiosResponse<T>> {
return HTTP.get(`/api/namespaces`)
}

export function reqSearch<T = any>(namespace: string, version: string, query: string, allowClasses: boolean, allowFields: boolean, allowMethods: boolean, limit: number = 50): Promise<AxiosResponse<T>> {
export function reqSearch<T = any>(namespace: string, version: string, query: string, allowClasses: boolean, allowFields: boolean, allowMethods: boolean,
abortController?: AbortController, limit: number = 50): Promise<AxiosResponse<T>> {
return HTTP.get(`/api/search`, {
signal: abortController?.signal,
params: {
namespace,
query,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/mappings/MappingsSearchBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default defineComponent({
this.timer = setTimeout(() => {
useMappingsStore().searchText = (event.target as any)?.value
}, 1000)
}, 300)
},
},
})
Expand All @@ -48,5 +48,6 @@ export default defineComponent({
<style scoped>
.input {
outline: 0 !important;
border: 0 !important;
}
</style>
4 changes: 3 additions & 1 deletion frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ HTTP.interceptors.response.use(response => {
NProgress.done()
return response
}, error => {
console.log(error)
if (!axios.isCancel(error)) {
console.log(error)
}
return Promise.reject(error)
})

Expand Down
7 changes: 5 additions & 2 deletions frontend/src/routes/Dependencies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default defineComponent({
formatMaven,
formatDependency,
tab,
reqVersionsPromise: undefined as Promise<any> | undefined,
}
},
computed: {
Expand Down Expand Up @@ -136,15 +137,17 @@ export default defineComponent({
},
methods: {
updateDependencyData() {
if (Object.keys(this.searchData.versions).length == 0) {
reqVersions().then(value => {
if (Object.keys(this.searchData.versions).length == 0 && !this.reqVersionsPromise) {
this.reqVersionsPromise = reqVersions().then(value => {
this.searchData.versions = value.data
this.ensureDependencyData()
}).catch(reason => {
addAlert({
type: "error",
message: `Failed to fetch versions: ${reason.message}`,
})
}).finally(() => {
this.reqVersionsPromise = undefined
})
}
},
Expand Down
74 changes: 46 additions & 28 deletions frontend/src/routes/Mappings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import MappingsSearchBlock from "../components/mappings/MappingsSearchBlock.vue"
import MappingsEntryBlock from "../components/mappings/MappingsEntryBlock.vue"
import MappingsFilterBlock from "../components/mappings/MappingsFilterBlock.vue"
import {VersionEntry} from "./Dependencies.vue"
import axios from "axios"
export interface Namespace {
id: string,
Expand Down Expand Up @@ -78,6 +79,8 @@ export default defineComponent({
entries: [],
fuzzy: false,
} as InfoData,
reqNamespacesPromise: undefined as Promise<any> | undefined,
searchController: undefined as AbortController | undefined,
}
},
computed: {
Expand Down Expand Up @@ -137,15 +140,17 @@ export default defineComponent({
},
methods: {
updateMappingsData() {
if (Object.keys(this.mappingsData.namespaces).length == 0) {
reqNamespaces().then(value => {
if (Object.keys(this.mappingsData.namespaces).length == 0 && !this.reqNamespacesPromise) {
this.reqNamespacesPromise = reqNamespaces().then(value => {
this.mappingsData.namespaces = value.data
this.ensureMappingsData()
}).catch(reason => {
addAlert({
type: "error",
message: `Failed to fetch namespaces: ${reason.message}`,
})
}).finally(() => {
this.reqNamespacesPromise = undefined
})
}
},
Expand All @@ -172,7 +177,11 @@ export default defineComponent({
if (namespace && version && searchText && (allowClasses || allowMethods || allowFields)) {
if (this.infoData.namespace !== namespace || this.infoData.version !== version || this.infoData.query !== searchText
|| this.infoData.allowClasses !== allowClasses || this.infoData.allowFields !== allowFields || this.infoData.allowMethods !== allowMethods) {
reqSearch(namespace, version, searchText, allowClasses, allowFields, allowMethods).then(value => {
if (this.searchController) {
this.searchController.abort()
}
this.searchController = new AbortController()
reqSearch(namespace, version, searchText, allowClasses, allowFields, allowMethods, this.searchController).then(value => {
if (value.data.error) {
if (value.data.error !== "No results found!") {
addAlert({
Expand All @@ -185,45 +194,54 @@ export default defineComponent({
return
}
this.infoData.fuzzy = value.data.fuzzy
this.infoData.entries = (value.data.entries as any[]).map(obj => {
let type: string
if (obj.t === "c") type = "class"
else if (obj.t === "f") type = "field"
else if (obj.t === "m") type = "method"
else type = obj.t
return {
obf: obj.o,
intermediary: obj.i,
named: obj.n,
descObf: obj.d,
descIntermediary: obj.e,
descNamed: obj.f,
ownerObf: obj.a,
ownerIntermediary: obj.b,
ownerNamed: obj.c,
type,
} as MappingEntry
})
this.infoData.entries = this.mapEntriesToMappingEntry(value.data.entries as any[])
}).catch(reason => {
addAlert({
type: "error",
message: `Failed to search: ${reason.message}`,
})
this.infoData.entries = []
this.infoData.fuzzy = false
if (!axios.isCancel(reason)) {
addAlert({
type: "error",
message: `Failed to search: ${reason.message}`,
})
this.infoData.entries = []
this.infoData.fuzzy = false
}
})
}
} else {
this.infoData.entries = []
this.infoData.fuzzy = false
}
this.setInfoDataToCurrent()
},
setInfoDataToCurrent() {
let {namespace, version, searchText, allowClasses, allowFields, allowMethods} = useMappingsStore()
this.infoData.namespace = namespace
this.infoData.version = version
this.infoData.query = searchText
this.infoData.allowClasses = allowClasses
this.infoData.allowMethods = allowMethods
this.infoData.allowFields = allowFields
},
mapEntriesToMappingEntry(entries: any[]) {
return entries.map(obj => {
let type: string
if (obj.t === "c") type = "class"
else if (obj.t === "f") type = "field"
else if (obj.t === "m") type = "method"
else type = obj.t
return {
obf: obj.o,
intermediary: obj.i,
named: obj.n,
descObf: obj.d,
descIntermediary: obj.e,
descNamed: obj.f,
ownerObf: obj.a,
ownerIntermediary: obj.b,
ownerNamed: obj.c,
type,
} as MappingEntry
})
},
},
})
</script>
Expand Down

0 comments on commit 54da54b

Please sign in to comment.