Created
August 6, 2020 16:30
-
-
Save shakalaca/82dcb27547ce885932215ec0cf08f566 to your computer and use it in GitHub Desktop.
Fix 403 limit exceeded error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt b/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt | |
index 81b3b8d..7529c8a 100644 | |
--- a/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt | |
+++ b/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt | |
@@ -42,7 +42,7 @@ class GithubRepository( | |
// appending '%' so we can allow other characters to be before and after the query string | |
val dbQuery = "%${query.replace(' ', '%')}%" | |
- val pagingSourceFactory = { database.reposDao().reposByName(dbQuery) } | |
+ val pagingSourceFactory = { database.reposDao().reposByIdx(dbQuery) } | |
return Pager( | |
config = PagingConfig(pageSize = NETWORK_PAGE_SIZE, enablePlaceholders = false), | |
diff --git a/app/src/main/java/com/example/android/codelabs/paging/db/RepoDao.kt b/app/src/main/java/com/example/android/codelabs/paging/db/RepoDao.kt | |
index b6d5714..763d6e4 100644 | |
--- a/app/src/main/java/com/example/android/codelabs/paging/db/RepoDao.kt | |
+++ b/app/src/main/java/com/example/android/codelabs/paging/db/RepoDao.kt | |
@@ -34,6 +34,11 @@ interface RepoDao { | |
"ORDER BY stars DESC, name ASC") | |
fun reposByName(queryString: String): PagingSource<Int, Repo> | |
+ @Query("SELECT * FROM repos WHERE " + | |
+ "name LIKE :queryString OR description LIKE :queryString " + | |
+ "ORDER BY idx ASC") | |
+ fun reposByIdx(queryString: String): PagingSource<Int, Repo> | |
+ | |
@Query("DELETE FROM repos") | |
suspend fun clearRepos() | |
diff --git a/app/src/main/java/com/example/android/codelabs/paging/model/Repo.kt b/app/src/main/java/com/example/android/codelabs/paging/model/Repo.kt | |
index 87fbc41..d854d19 100644 | |
--- a/app/src/main/java/com/example/android/codelabs/paging/model/Repo.kt | |
+++ b/app/src/main/java/com/example/android/codelabs/paging/model/Repo.kt | |
@@ -28,7 +28,8 @@ import com.google.gson.annotations.SerializedName | |
*/ | |
@Entity(tableName = "repos") | |
data class Repo( | |
- @PrimaryKey @field:SerializedName("id") val id: Long, | |
+ @PrimaryKey(autoGenerate = true) val idx: Long, | |
+ @field:SerializedName("id") val id: Long, | |
@field:SerializedName("name") val name: String, | |
@field:SerializedName("full_name") val fullName: String, | |
@field:SerializedName("description") val description: String?, | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment