Skip to content

Commit 73683e8

Browse files
committed
Issue #340 Re-think targeting Input
1 parent 29585a4 commit 73683e8

File tree

13 files changed

+1118
-739
lines changed

13 files changed

+1118
-739
lines changed

Cargo.lock

Lines changed: 140 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adview-manager/src/lib.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use adex_primitives::{
55
supermarket::units_for_slot,
66
supermarket::units_for_slot::response::{AdUnit, Campaign},
7-
targeting::{self, input, Value},
7+
targeting::{self, input},
88
BigNum, ChannelId, SpecValidators, ValidatorId, IPFS,
99
};
1010
use async_std::{sync::RwLock, task::block_on};
@@ -323,10 +323,9 @@ impl Manager {
323323
})
324324
.unwrap_or(u64::MAX);
325325

326-
input.set_ad_view(input::AdView {
326+
input.ad_view = Some(input::AdView {
327327
seconds_since_campaign_impression,
328328
has_custom_preferences: false,
329-
// TODO: Check this empty default!
330329
navigator_language: self.options.navigator_language.clone().unwrap_or_default(),
331330
});
332331

@@ -411,7 +410,6 @@ impl Manager {
411410
.collect::<Vec<_>>()
412411
.join("&");
413412

414-
415413
// Url adds a trailing `/`
416414
let url = format!(
417415
"{}units-for-slot/{}?pubPrefix={}&{}",
@@ -436,17 +434,12 @@ impl Manager {
436434
let units_for_slot = self.get_market_demand_resp().await?;
437435
let campaigns = &units_for_slot.campaigns;
438436
let fallback_unit = units_for_slot.fallback_unit;
439-
let targeting_input = input::Getter {
440-
base: units_for_slot.targeting_input_base,
441-
ad_unit: None,
442-
channel: None,
443-
last_approved: None,
444-
deposit_asset: None,
445-
};
437+
let targeting_input = units_for_slot.targeting_input_base;
446438

447439
let hostname = targeting_input
448-
.try_get("adSlot.hostname")
449-
.and_then(Value::try_string)
440+
.ad_slot
441+
.as_ref()
442+
.map(|ad_slot| ad_slot.hostname.clone())
450443
.unwrap_or_default();
451444

452445
// Stickiness is when we keep showing an ad unit for a slot for some time in order to achieve fair impression value
@@ -475,15 +468,17 @@ impl Manager {
475468
if block_on(self.is_campaign_sticky(campaign.channel.id)) {
476469
return vec![];
477470
}
478-
let mut campaign_input = targeting_input.clone();
471+
479472
let campaign_id = campaign.channel.id;
480-
campaign_input.channel = Some(campaign.channel.clone());
473+
474+
let campaign_input = targeting_input.clone().with_market_channel(campaign.channel.clone());
481475

482476
campaign
483477
.units_with_price
484478
.iter()
485479
.filter(|unit_with_price| {
486-
campaign_input.ad_unit = Some(unit_with_price.unit.clone());
480+
let mut unit_input = campaign_input.clone();
481+
unit_input.ad_unit_id = Some(unit_with_price.unit.id.clone());
487482

488483
let mut output = targeting::Output {
489484
show: true,
@@ -497,7 +492,7 @@ impl Manager {
497492

498493
targeting::eval_with_callback(
499494
&campaign.targeting_rules,
500-
&input::Input::Getter(campaign_input.clone()),
495+
&unit_input,
501496
&mut output,
502497
Some(on_type_error)
503498
);

primitives/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ serde = { version = "^1.0", features = ['derive'] }
1313
serde_json = "1.0"
1414
serde-hex = "0.1.0"
1515
serde_millis = "0.1.1"
16+
# Used prefixes on field for targeting::Input
17+
serde_with = "1.5"
1618
# Configuration
1719
toml = "0.5"
1820
# Logging
@@ -23,6 +25,8 @@ slog-async = "^2.3.0"
2325
thiserror = "^1.0"
2426
chrono = { version = "0.4", features = ["serde"] }
2527
time = "0.1.42"
28+
# Macro for easier derive of Display & FromStr
29+
parse-display = "^0.3"
2630
# CID & multihash / multibase
2731
cid = "0.5"
2832
hex = "0.4"
@@ -47,3 +51,6 @@ futures = "0.3"
4751
async-trait = "0.1.40"
4852
# Other
4953
lazy_static = "1.4.0"
54+
55+
[dev-dependencies]
56+
pretty_assertions = "^0.6"

primitives/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub mod merkle_tree;
1818
pub mod sentry;
1919
pub mod supermarket;
2020
pub mod targeting;
21-
pub mod targeting_tag;
2221

2322
pub mod util {
2423
pub mod tests {
@@ -48,7 +47,6 @@ pub use self::channel::{Channel, ChannelId, ChannelSpec, SpecValidator, SpecVali
4847
pub use self::config::Config;
4948
pub use self::event_submission::EventSubmission;
5049
pub use self::ipfs::IPFS;
51-
pub use self::targeting_tag::TargetingTag;
5250
pub use self::validator::{ValidatorDesc, ValidatorId};
5351

5452
#[derive(Debug, PartialEq, Eq)]

primitives/src/supermarket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod units_for_slot {
4444
pub mod response {
4545

4646
use crate::{
47-
targeting::{Map, Rule},
47+
targeting::{Input, Rule},
4848
BigNum, ChannelId, ChannelSpec, SpecValidators, ValidatorId, IPFS,
4949
};
5050
use chrono::{
@@ -57,7 +57,7 @@ pub mod units_for_slot {
5757
#[derive(Debug, Serialize, Deserialize, PartialEq)]
5858
#[serde(rename_all = "camelCase")]
5959
pub struct Response {
60-
pub targeting_input_base: Map,
60+
pub targeting_input_base: Input,
6161
pub accepted_referrers: Vec<Url>,
6262
pub fallback_unit: Option<AdUnit>,
6363
pub campaigns: Vec<Campaign>,

0 commit comments

Comments
 (0)