@@ -61,46 +61,51 @@ class RepoUpdater(repoData2: RepoData) {
6161 val moduleListCacheDao = db.moduleListCacheDao()
6262 // now we have the cache, we need to check if it's up to date
6363 val results = moduleListCacheDao.getByRepoId(repoData.preferenceId!! )
64- toUpdate = emptyList()
65- toApply = HashSet ()
66- for (moduleListCache in results) {
67- (toApply as HashSet <RepoModule >).add(
68- RepoModule (
69- repoData,
70- moduleListCache.codename,
71- moduleListCache.name,
72- moduleListCache.description,
73- moduleListCache.author,
74- moduleListCache.donate,
75- moduleListCache.config,
76- moduleListCache.support,
77- moduleListCache.version,
78- moduleListCache.versionCode
64+ if (results.isNotEmpty()) {
65+ toUpdate = emptyList()
66+ toApply = HashSet ()
67+ for (moduleListCache in results) {
68+ (toApply as HashSet <RepoModule >).add(
69+ RepoModule (
70+ repoData,
71+ moduleListCache.codename,
72+ moduleListCache.name,
73+ moduleListCache.description,
74+ moduleListCache.author,
75+ moduleListCache.donate,
76+ moduleListCache.config,
77+ moduleListCache.support,
78+ moduleListCache.version,
79+ moduleListCache.versionCode
80+ )
7981 )
82+ }
83+ Timber .d(
84+ " Fetched %d modules from cache for %s, from %s records" ,
85+ (toApply as HashSet <RepoModule >).size,
86+ repoData.preferenceId,
87+ results.size
8088 )
89+ val jsonObject = JSONObject ()
90+ // apply the toApply list to the toUpdate list
91+ try {
92+ jsonObject.put(" modules" , JSONArray (results))
93+ toUpdate = repoData.populate(jsonObject)
94+ } catch (e: Exception ) {
95+ Timber .e(e)
96+ }
97+ // log first 100 chars of indexRaw
98+ indexRaw = jsonObject.toString().toByteArray()
99+ Timber .d(
100+ " Index raw: %s" ,
101+ String (indexRaw!! , StandardCharsets .UTF_8 ).subSequence(0 , 100 )
102+ )
103+ // Since we reuse instances this should work
104+ toApply = HashSet (repoData.moduleHashMap.values)
105+ (toApply as HashSet <RepoModule >).removeAll(toUpdate!! .toSet())
106+ // Return repo to update
107+ return toUpdate!! .size
81108 }
82- Timber .d(
83- " Fetched %d modules from cache for %s, from %s records" ,
84- (toApply as HashSet <RepoModule >).size,
85- repoData.preferenceId,
86- results.size
87- )
88- val jsonObject = JSONObject ()
89- // apply the toApply list to the toUpdate list
90- try {
91- jsonObject.put(" modules" , JSONArray (results))
92- toUpdate = repoData.populate(jsonObject)
93- } catch (e: Exception ) {
94- Timber .e(e)
95- }
96- // log first 100 chars of indexRaw
97- indexRaw = jsonObject.toString().toByteArray()
98- Timber .d(" Index raw: %s" , String (indexRaw!! , StandardCharsets .UTF_8 ).subSequence(0 , 100 ))
99- // Since we reuse instances this should work
100- toApply = HashSet (repoData.moduleHashMap.values)
101- (toApply as HashSet <RepoModule >).removeAll(toUpdate!! .toSet())
102- // Return repo to update
103- return toUpdate!! .size
104109 }
105110 return try {
106111 if (! repoData.prepare()) {
0 commit comments