Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
cb3f9b97
Commit
cb3f9b97
authored
Aug 02, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tweaking to Rx pipeline
parent
97843532
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
23 deletions
+22
-23
RepoDao.kt
...c/main/java/com/topjohnwu/magisk/data/database/RepoDao.kt
+2
-2
RepoUpdater.kt
app/src/main/java/com/topjohnwu/magisk/tasks/RepoUpdater.kt
+20
-21
No files found.
app/src/main/java/com/topjohnwu/magisk/data/database/RepoDao.kt
View file @
cb3f9b97
...
...
@@ -7,7 +7,7 @@ import com.topjohnwu.magisk.model.entity.module.Repo
@Dao
abstract
class
RepoDao
{
val
repoID
Set
:
Set
<
String
>
get
()
=
getRepoID
().
map
{
it
.
id
}.
toSet
()
val
repoID
List
get
()
=
getRepoID
().
map
{
it
.
id
}
val
repos
:
List
<
Repo
>
get
()
=
when
(
Config
.
repoOrder
)
{
Config
.
Value
.
ORDER_NAME
->
getReposNameOrder
()
...
...
@@ -45,7 +45,7 @@ abstract class RepoDao {
abstract
fun
removeRepo
(
id
:
String
)
@Query
(
"DELETE FROM repos WHERE id IN (:idList)"
)
abstract
fun
removeRepos
(
idList
:
List
<
String
>)
abstract
fun
removeRepos
(
idList
:
Collection
<
String
>)
@Query
(
"SELECT * FROM etag"
)
protected
abstract
fun
etagRaw
():
RepoEtag
?
...
...
app/src/main/java/com/topjohnwu/magisk/tasks/RepoUpdater.kt
View file @
cb3f9b97
...
...
@@ -7,6 +7,7 @@ import com.topjohnwu.magisk.data.network.GithubApiServices
import
com.topjohnwu.magisk.model.entity.module.Repo
import
io.reactivex.Flowable
import
io.reactivex.Single
import
io.reactivex.rxkotlin.toFlowable
import
io.reactivex.schedulers.Schedulers
import
se.ansman.kotshi.JsonSerializable
import
timber.log.Timber
...
...
@@ -21,16 +22,13 @@ class RepoUpdater(
)
{
private
fun
loadRepos
(
repos
:
List
<
GithubRepoInfo
>,
cached
:
MutableSet
<
String
>)
=
Flowable
.
fromIterable
(
repos
).
map
{
it
.
id
to
dateFormat
.
parse
(
it
.
pushed_at
)
!!
}.
parallel
().
runOn
(
Schedulers
.
io
()).
map
{
repos
.
toFlowable
().
parallel
().
runOn
(
Schedulers
.
io
()).
map
{
// Skip submission
if
(
it
.
first
==
"submission"
)
if
(
it
.
id
==
"submission"
)
return
@map
(
repoDB
.
getRepo
(
it
.
first
)
?.
apply
{
cached
.
remove
(
it
.
first
)
}
?:
Repo
(
it
.
first
)).
runCatching
{
update
(
it
.
second
)
(
repoDB
.
getRepo
(
it
.
id
)
?.
apply
{
cached
.
remove
(
it
.
id
)
}
?:
Repo
(
it
.
id
)).
runCatching
{
update
(
it
.
pushDate
)
repoDB
.
addRepo
(
this
)
}.
getOrElse
{
Timber
.
e
(
it
)
}
}.
sequential
()
...
...
@@ -57,8 +55,8 @@ class RepoUpdater(
}
}
private
fun
forcedReload
(
cached
:
MutableSet
<
String
>)
=
Flowable
.
fromIterable
(
cached
)
.
parallel
().
runOn
(
Schedulers
.
io
()).
map
{
private
fun
forcedReload
(
cached
:
MutableSet
<
String
>)
=
cached
.
toFlowable
()
.
parallel
().
runOn
(
Schedulers
.
io
()).
map
{
runCatching
{
Repo
(
it
).
update
()
}.
getOrElse
{
Timber
.
e
(
it
)
}
...
...
@@ -67,9 +65,9 @@ class RepoUpdater(
private
fun
String
.
trimEtag
()
=
substring
(
indexOf
(
'\"'
),
lastIndexOf
(
'\"'
)
+
1
)
operator
fun
invoke
(
forced
:
Boolean
=
false
)
:
Single
<
Unit
>
{
val
cached
=
Collections
.
synchronizedSet
(
HashSet
(
repoDB
.
repoID
Se
t
))
val
cached
=
Collections
.
synchronizedSet
(
HashSet
(
repoDB
.
repoID
Lis
t
))
return
loadPage
(
cached
,
etag
=
repoDB
.
etagKey
).
doOnComplete
{
repoDB
.
removeRepos
(
cached
.
toList
()
)
repoDB
.
removeRepos
(
cached
)
}.
onErrorResumeNext
{
it
:
Throwable
->
if
(
it
is
CachedException
)
{
if
(
forced
)
...
...
@@ -78,21 +76,22 @@ class RepoUpdater(
Timber
.
e
(
it
)
}
Flowable
.
empty
()
}.
collect
({},
{
_
,
_
->
}
)
}.
ignoreElements
().
toSingleDefault
(
Unit
)
}
companion
object
{
private
val
dateFormat
:
SimpleDateFormat
=
object
CachedException
:
Exception
()
}
private
val
dateFormat
:
SimpleDateFormat
=
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
,
Locale
.
US
).
apply
{
timeZone
=
TimeZone
.
getTimeZone
(
"UTC"
)
}
}
object
CachedException
:
Exception
()
}
@JsonSerializable
data class
GithubRepoInfo
(
@Json
(
name
=
"name"
)
val
id
:
String
,
val
pushed_at
:
String
)
\ No newline at end of file
)
{
@Transient
val
pushDate
=
dateFormat
.
parse
(
pushed_at
)
!!
}
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