Skip to content

Add checksumMd5 column to Image table #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged

Conversation

tuancoltech
Copy link
Member

@tuancoltech tuancoltech commented Jun 13, 2025

Issue Number

Purpose

  • Add checksumMd5 column to Image table
  • Use checksumMd5 to read image files from disk

Technical Details

Screenshots

Testing Instructions

Regression Tests

  • I tested my changes on Android 16 (API 36)
  • I tested my changes on Android 15 (API 35)
  • I tested my changes on Android 14 (API 34)
  • I tested my changes on Android 13 (API 33)
  • I tested my changes on Android 12L (API 32)
  • I tested my changes on Android 12 (API 31)
  • I tested my changes on Android 11 (API 30)
  • I tested my changes on Android 10 (API 29)
  • I tested my changes on Android 9 (API 28)
  • I tested my changes on Android 8.1 (API 27)
  • I tested my changes on Android 8.0 (API 26)

UI Tests

  • I tested my changes on a 6-7" screen (▯ portrait orientation)
  • I tested my changes on a 6-7" screen (▭ landscape orientation)
  • I tested my changes on a 7-8" screen (▯ portrait orientation)
  • I tested my changes on a 7-8" screen (▭ landscape orientation)
  • I tested my changes on a 9-10" screen (▯ portrait orientation)
  • I tested my changes on a 9-10" screen (▭ landscape orientation)

Content Tests

  • I tested my changes with English content (eng.elimu.ai)
  • I tested my changes with Hindi content (hin.elimu.ai)
  • I tested my changes with Tagalog content (tgl.elimu.ai)
  • I tested my changes with Thai content (tha.elimu.ai)
  • I tested my changes with Vietnamese content (vie.elimu.ai)

Summary by CodeRabbit

  • New Features

    • Added support for storing and displaying the MD5 checksum for images.
  • Bug Fixes

    • Improved image file naming by using the image's checksum, ensuring unique and consistent filenames.
  • Chores

    • Updated the database schema to version 30, including migration support for the new image checksum field.

@tuancoltech tuancoltech requested a review from a team as a code owner June 13, 2025 08:22
@tuancoltech tuancoltech requested a review from jo-elimu June 13, 2025 08:22
Copy link

coderabbitai bot commented Jun 13, 2025

Walkthrough

This change introduces database schema version 30, adding a checksumMd5 field to the Image entity and updating related Room migration logic. The Gson-to-Room converter and file helper are updated to use checksumMd5 for image file naming and storage. No other logic or control flow is altered.

Changes

File(s) Change Summary
app/schemas/ai.elimu.content_provider.room.db.RoomDb/30.json Added Room database schema version 30 with updated entities and relationships.
app/src/main/java/ai/elimu/content_provider/room/db/RoomDb.java Incremented DB version to 30; added migration to include checksumMd5 in Image table.
app/src/main/java/ai/elimu/content_provider/room/entity/Image.kt Added checksumMd5 property to Image entity.
app/src/main/java/ai/elimu/content_provider/room/GsonToRoomConverter.kt Updated Image conversion to set checksumMd5 from Gson object.
app/src/main/java/ai/elimu/content_provider/util/FileHelper.kt Changed image file naming to use checksumMd5 instead of ID and revision number.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant GsonToRoomConverter
    participant RoomDb
    participant FileHelper

    App->>GsonToRoomConverter: Convert ImageGson to Image
    GsonToRoomConverter->>Image: Set checksumMd5 property
    App->>RoomDb: Store Image entity (with checksumMd5)
    App->>FileHelper: Request image file for Image
    FileHelper->>File: Generate filename using checksumMd5
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure images appear in the app by fixing the ImageProvider to provide images correctly (#355)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs


elimu.ai's mission is to build innovative learning software that empowers out-of-school children to teach themselves basic reading📖, writing✍🏽 and math🔢 within 6 months.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (2)
app/src/main/java/ai/elimu/content_provider/util/FileHelper.kt (2)

18-27: 🛠️ Refactor suggestion

Validation still checks id/revisionNumber instead of checksumMd5

The early-return guard is now irrelevant to the new naming scheme and may block valid images whose IDs were trimmed from the feed.

-if ((imageGson.id == null) || (imageGson.revisionNumber == null)) {
+if (imageGson.checksumMd5.isNullOrBlank()) {
     return null
 }

32-41: 🛠️ Refactor suggestion

Duplicate issue in entity overload

Same mismatch as above; validate checksumMd5, not the obsolete fields.

-if ((imageGson.id == null) || (imageGson.revisionNumber == null)) {
+if (imageGson.checksumMd5.isBlank()) {
     return null
 }
🧹 Nitpick comments (2)
app/src/main/java/ai/elimu/content_provider/room/entity/Image.kt (1)

14-14: Consider avoiding lateinit for a database-backed NOT NULL column

lateinit var checksumMd5: String silently allows the field to be left unset in Kotlin code until first access, hiding bugs until runtime.
Prefer an explicit non-nullable constructor parameter or default value:

var checksumMd5: String = ""

This keeps compile-time guarantees aligned with the NOT NULL schema.

app/src/main/java/ai/elimu/content_provider/room/db/RoomDb.java (1)

402-409: Incorrect Log.i usage prints a literal %s

Log.i(String tag, String msg) does not perform printf-style formatting:

Log.i("migrate sql: %s", sql);

Results in tag = "migrate sql: %s" and message = sql.
Use proper formatting to avoid confusing logcat output:

-Log.i("migrate sql: %s", sql);
+Log.i(getClass().getName(), String.format("migrate sql: %s", sql));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31d5248 and 314cd1b.

📒 Files selected for processing (5)
  • app/schemas/ai.elimu.content_provider.room.db.RoomDb/30.json (1 hunks)
  • app/src/main/java/ai/elimu/content_provider/room/GsonToRoomConverter.kt (1 hunks)
  • app/src/main/java/ai/elimu/content_provider/room/db/RoomDb.java (3 hunks)
  • app/src/main/java/ai/elimu/content_provider/room/entity/Image.kt (1 hunks)
  • app/src/main/java/ai/elimu/content_provider/util/FileHelper.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build (macos-latest, 21)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: test (29)
  • GitHub Check: test (28)
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: build (macos-latest, 17)
  • GitHub Check: lint
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (ubuntu-latest, 17)
🔇 Additional comments (2)
app/src/main/java/ai/elimu/content_provider/room/GsonToRoomConverter.kt (1)

160-165:

❓ Verification inconclusive

Guard against nullable checksumMd5 before assignment

Image.checksumMd5 is lateinit var and marked NOT NULL in the DB.
If imageGson.checksumMd5 arrives as null (or blank) this line will throw at runtime or violate the column constraint, jeopardising elimu.ai's mission to build innovative learning software that empowers out-of-school children to teach themselves basic reading📖, writing✍🏽 and math🔢 within 6 months.

-// Image
-image.title = imageGson.title
-image.imageFormat = imageGson.imageFormat
-image.checksumMd5 = imageGson.checksumMd5
+// Image
+image.title = imageGson.title
+image.imageFormat = imageGson.imageFormat
+image.checksumMd5 = requireNotNull(imageGson.checksumMd5) {
+    "checksumMd5 must be non-null for image id=${imageGson.id}"
+}

To uphold elimu.ai’s mission to build innovative learning software that empowers out-of-school children to teach themselves basic reading📖, writing✍🏽 and math🔢 within 6 months, let’s verify the nullability of checksumMd5 in both the JSON model and the Room entity:


🏁 Script executed:

#!/bin/bash
# Locate and show the ImageGson declaration
echo "=== ImageGson Definition ==="
rg --color=never -n "data class ImageGson" -A3 || echo "ImageGson class not found"

echo
# Show checksumMd5 property in ImageGson
echo "=== checksumMd5 in ImageGson ==="
rg --color=never -n "checksumMd5" -B1 -A1 || echo "checksumMd5 not found in ImageGson"

echo
# Locate and show the Room Image entity declaration
echo "=== Image Entity Definition ==="
rg --color=never -n "class Image" -A3 || echo "Image entity not found"

echo
# Show checksumMd5 property in Image entity
echo "=== checksumMd5 in Image Entity ==="
rg --color=never -n "checksumMd5" -B1 -A1 || echo "checksumMd5 not found in Image entity"

Length of output: 7737


To confirm whether imageGson.checksumMd5 can actually be null, let’s locate and inspect the ImageGson class definition:


🏁 Script executed:

#!/bin/bash
# List all files referencing ImageGson
echo "=== Files containing ImageGson ==="
rg --color=never -l "ImageGson" || echo "No references found"

# For each, show nearby class declaration and property definitions
for file in $(rg --color=never -l "ImageGson"); do
  echo
  echo "=== Inspecting $file ==="
  rg --color=never -n "class ImageGson|data class ImageGson" -A5 -B2 "$file" || echo "No class keyword around ImageGson"
done

Length of output: 5365


Verify nullability of checksumMd5 in ImageGson before assignment

To uphold elimu.ai’s mission to build innovative learning software that empowers out-of-school children to teach themselves basic reading📖, writing✍🏽 and math🔢 within 6 months, we must ensure no runtime or DB NOT NULL violations creep in.

• File: app/src/main/java/ai/elimu/content_provider/room/GsonToRoomConverter.kt
Line 163: image.checksumMd5 = imageGson.checksumMd5
Image.checksumMd5 is a lateinit var mapped to a TEXT NOT NULL column.
• We couldn’t locate the ImageGson class in source—please confirm if its checksumMd5 property is nullable (String?) or always non-null.

If it can be null or blank, guard or default it, for example:

image.checksumMd5 = requireNotNull(imageGson.checksumMd5) {
    "checksumMd5 must be non-null for image id=${imageGson.id}"
}
// or, to allow empty strings:
image.checksumMd5 = imageGson.checksumMd5.orEmpty()
app/schemas/ai.elimu.content_provider.room.db.RoomDb/30.json (1)

320-366: Schema looks consistent with code changes – nice work

checksumMd5 is declared TEXT NOT NULL, matching the entity and migration.
No further action needed.

@tuancoltech tuancoltech merged commit 90c502e into main Jun 13, 2025
9 checks passed
@tuancoltech tuancoltech deleted the add-checksummd5-column branch June 13, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImageProvider fails to provide images
2 participants