Skip to content

Commit

Permalink
Move the file read/write to IO thread (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored May 31, 2024
1 parent 3b24959 commit 0d112a9
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 148 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.7.45"
version = "1.7.46"

repositories {
google()
Expand Down
220 changes: 125 additions & 95 deletions integration/iOS/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -260,27 +260,37 @@ class AsyncAbacusStateManager(
}

private fun load(configFile: ConfigFile) {
val path = configFile.path
if (appConfigs.loadRemote) {
loadFromRemoteConfigFile(configFile)
val configFileUrl = "$deploymentUri$path"
ioImplementations.rest?.get(configFileUrl, null, callback = { response, httpCode, _ ->
if (success(httpCode) && response != null) {
if (parse(response, configFile)) {
writeToLocalFile(response, path)
}
}
})
} else {
loadFromBundledLocalConfigFile(configFile)
ioImplementations.threading?.async(ThreadingType.network) {
val path = configFile.path
if (appConfigs.loadRemote) {
loadFromRemoteConfigFile(configFile)
val configFileUrl = "$deploymentUri$path"
ioImplementations.rest?.get(
configFileUrl,
null,
callback = { response, httpCode, _ ->
ioImplementations.threading?.async(ThreadingType.abacus) {
if (success(httpCode) && response != null) {
if (parse(response, configFile)) {
writeToLocalFile(response, path)
}
}
}
},
)
} else {
loadFromBundledLocalConfigFile(configFile)
}
}
}

private fun loadFromRemoteConfigFile(configFile: ConfigFile) {
ioImplementations.fileSystem?.readCachedTextFile(
configFile.path,
)?.let {
parse(it, configFile)
ioImplementations.threading?.async(ThreadingType.abacus) {
parse(it, configFile)
}
}
}

Expand All @@ -289,7 +299,9 @@ class AsyncAbacusStateManager(
FileLocation.AppBundle,
configFile.path,
)?.let {
parse(it, configFile)
ioImplementations.threading?.async(ThreadingType.abacus) {
parse(it, configFile)
}
}
}

Expand All @@ -309,10 +321,12 @@ class AsyncAbacusStateManager(
}

private fun writeToLocalFile(response: String, file: String) {
ioImplementations.fileSystem?.writeTextFile(
file,
response,
)
ioImplementations.threading?.async(ThreadingType.network) {
ioImplementations.fileSystem?.writeTextFile(
file,
response,
)
}
}

private fun parseDocumentation(response: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,37 @@ class AsyncAbacusStateManagerV2(
}

private fun load(configFile: ConfigFile) {
val path = configFile.path
if (appConfigs.loadRemote) {
loadFromRemoteConfigFile(configFile)
val configFileUrl = "$deploymentUri$path"
ioImplementations.rest?.get(configFileUrl, null, callback = { response, httpCode, headers ->
if (success(httpCode) && response != null) {
if (parse(response, configFile)) {
writeToLocalFile(response, path)
}
}
})
} else {
loadFromBundledLocalConfigFile(configFile)
ioImplementations.threading?.async(ThreadingType.network) {
val path = configFile.path
if (appConfigs.loadRemote) {
loadFromRemoteConfigFile(configFile)
val configFileUrl = "$deploymentUri$path"
ioImplementations.rest?.get(
configFileUrl,
null,
callback = { response, httpCode, headers ->
ioImplementations.threading?.async(ThreadingType.abacus) {
if (success(httpCode) && response != null) {
if (parse(response, configFile)) {
writeToLocalFile(response, path)
}
}
}
},
)
} else {
loadFromBundledLocalConfigFile(configFile)
}
}
}

private fun loadFromRemoteConfigFile(configFile: ConfigFile) {
ioImplementations.fileSystem?.readCachedTextFile(
configFile.path,
)?.let {
parse(it, configFile)
ioImplementations.threading?.async(ThreadingType.abacus) {
parse(it, configFile)
}
}
}

Expand All @@ -311,7 +321,9 @@ class AsyncAbacusStateManagerV2(
FileLocation.AppBundle,
configFile.path,
)?.let {
parse(it, configFile)
ioImplementations.threading?.async(ThreadingType.abacus) {
parse(it, configFile)
}
}
}

Expand All @@ -331,10 +343,12 @@ class AsyncAbacusStateManagerV2(
}

private fun writeToLocalFile(response: String, file: String) {
ioImplementations.fileSystem?.writeTextFile(
file,
response,
)
ioImplementations.threading?.async(ThreadingType.network) {
ioImplementations.fileSystem?.writeTextFile(
file,
response,
)
}
}

private fun parseDocumentation(response: String) {
Expand Down
4 changes: 2 additions & 2 deletions v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.7.45'
spec.version = '1.7.46'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand All @@ -11,7 +11,7 @@ Pod::Spec.new do |spec|



if !Dir.exist?('build/cocoapods/framework/Abacus.framework') || Dir.empty?('build/cocoapods/framework/Abacus.framework')
if false
raise "
Kotlin framework 'Abacus' doesn't exist yet, so a proper Xcode project can't be generated.
Expand Down

0 comments on commit 0d112a9

Please sign in to comment.