Skip to content

feat: Adds secondary sqlite db to ads-client - #7567

Open
thesuzerain wants to merge 14 commits into
mainfrom
ads-client-adds-secondary-sqlite-db
Open

feat: Adds secondary sqlite db to ads-client#7567
thesuzerain wants to merge 14 commits into
mainfrom
ads-client-adds-secondary-sqlite-db

Conversation

@thesuzerain

@thesuzerain thesuzerain commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

This adds an 'adstore' equivalent to the to be used for storing ads in the new stateful ads-client design. It does not provide any FFI or interfaces or hooks or anything, simply the sqlite queries and internal logic, mimickingmost of the logic for the http_cache. This uses a separate sqlite db to the http_cache one, though they are functionally quite similar. The tests are all similar/the same, except for removed ones (such as TTL tests, see below).

In particular, this does not include:

  • In-memory database fallback: We have confirmation on this being OK to try, but for now this currently simply stores the AdsStore as None if the proper db path is not provided in setup. The in-memory db can be added in another PR after as a default.
  • TTL: Because the TTL strategy will look different for this than the http_cache (we will have a background worker thread updating + clearing) it's not included in this PR .
  • Expanded telemetry (eg: http_cache has record_http_cache_outcome for cache hits/misses)

I did, however, keep the following modules:

  • bytesize (as max_size will still be relevant here)
  • clock + stored_at (as this will almost certainly be relevant to TTL later)

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

pub placement_id: PlacementId,
pub ad_type: StorableAdType,
pub ad_body: Vec<u8>,
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This struct isn't strictly needed at this moment, but it makes the test generation a bit cleaner, and I could see it being useful for the next PR in the process (which will likely utilize conversions from AdImage, etc, to a more generic structure- this one)

@thesuzerain
thesuzerain requested a review from Almaju August 31, 2026 19:22
@thesuzerain
thesuzerain marked this pull request as ready for review August 31, 2026 19:22
@thesuzerain
thesuzerain requested a review from a team as a code owner August 31, 2026 19:22
pub struct AdsStoreBuilder {
db_path: PathBuf,
max_size: Option<ByteSize>,
}

@thesuzerain thesuzerain Aug 31, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We keep max_size in the builder but it's not publically exposed ATM, as discussed. Options like this will be accessible by surfaces as needed.

pub store_config: Option<AdsStoreConfig>,
pub context_id_provider: Option<Box<dyn super::ContextIdProvider>>,
pub environment: Environment,
pub telemetry: T,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: we could keep alphabetical order here, I have written an article about alphabetical sorting if you are curious why I think it's important https://almaju.github.io/blog/docs/fundamentals/style/sorting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(also there are other places of the diffs where we could keep alphabetical sorting but I only commented here)

})
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code feels like a lot for just storing the ad type. I think there are other ways we could explore.

  1. We could store it as an enum like:
#[derive(Serialize, Deserialize)]
#[serde(tag = "type")]
enum Ad {
    Image(Image),
    Tile(Tile),
}

and then we can use the type field in the json?

  1. Or we could even use something like std::any::type_name::<MyStruct>() to get the type as a string?

  2. I feel like we would know the type at deserialization anyway so instead of those wrapper type we could just have something like:

fn lookup<T: Deserialize>(...) -> Result<T>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh! And I realize that code lives under mars which should only be JSON API logic, not store logic!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like that we put these common things out but I feel database is not the right name, bytesize and clock are unrelated to database, I would rename it to something like "core", "primitives", "common", "support" etc.?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or we could even move them to ads_store directly if we expect they will be only used by ads_store in the future?

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.

2 participants