| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a366611 commit cd003d7
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ import org.joda.time.DateTime | |||
| 9 | 9 | case class DfpLineItems(validItems: Seq[GuLineItem], invalidItems: Seq[GuLineItem]) | |
| 10 | 10 | ||
| 11 | 11 | class DfpApi(dataMapper: DataMapper, dataValidation: DataValidation) extends Logging { | |
| 12 | - import DfpApi._ | ||
| 12 | + import dfp.DfpApi._ | ||
| 13 | 13 | ||
| 14 | 14 | private def readLineItems(stmtBuilder: StatementBuilder): DfpLineItems = { | |
| 15 | 15 | ||
@@ -63,6 +63,19 @@ class DfpApi(dataMapper: DataMapper, dataValidation: DataValidation) extends Log | |||
| 63 | 63 | readLineItems(stmtBuilder) | |
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | + def readSponsorshipLineItemIds(): Seq[Long] = { | ||
| 67 | + | ||
| 68 | + val stmtBuilder = new StatementBuilder() | ||
| 69 | + .where("(status = :readyStatus OR status = :deliveringStatus) AND lineItemType = :sponsorshipType") | ||
| 70 | + .withBindVariableValue("readyStatus", ComputedStatus.READY.toString) | ||
| 71 | + .withBindVariableValue("deliveringStatus", ComputedStatus.DELIVERING.toString) | ||
| 72 | + .withBindVariableValue("sponsorshipType", LineItemType.SPONSORSHIP.toString) | ||
| 73 | + .orderBy("id ASC") | ||
| 74 | + | ||
| 75 | + val lineItems = readLineItems(stmtBuilder) | ||
| 76 | + (lineItems.validItems.map(_.id) ++ lineItems.invalidItems.map(_.id)).sorted | ||
| 77 | + } | ||
| 78 | + | ||
| 66 | 79 | def readActiveCreativeTemplates(): Seq[GuCreativeTemplate] = { | |
| 67 | 80 | ||
| 68 | 81 | val stmtBuilder = new StatementBuilder() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,9 +22,11 @@ class DfpDataCacheJob(adUnitAgent: AdUnitAgent, | |||
| 22 | 22 | log.info("Refreshing data cache") | |
| 23 | 23 | val start = System.currentTimeMillis | |
| 24 | 24 | val data = loadLineItems() | |
| 25 | + val sponsorshipLineItemIds = dfpApi.readSponsorshipLineItemIds() | ||
| 25 | 26 | val duration = System.currentTimeMillis - start | |
| 26 | 27 | log.info(s"Loading DFP data took $duration ms") | |
| 27 | 28 | write(data) | |
| 29 | + Store.putNonRefreshableLineItemIds(sponsorshipLineItemIds) | ||
| 28 | 30 | } | |
| 29 | 31 | ||
| 30 | 32 | /* | |
@@ -88,7 +90,7 @@ class DfpDataCacheJob(adUnitAgent: AdUnitAgent, | |||
| 88 | 90 | val recentlyModified = lineItemsModifiedSince(threshold) | |
| 89 | 91 | ||
| 90 | 92 | // Update existing items with a patch of new items. | |
| 91 | - def updateCachedContent(existingItems: Seq[GuLineItem], newItems: Seq[GuLineItem], logging: Boolean = true): Seq[GuLineItem] = { | ||
| 93 | + def updateCachedContent(existingItems: Seq[GuLineItem], newItems: Seq[GuLineItem]): Seq[GuLineItem] = { | ||
| 92 | 94 | ||
| 93 | 95 | // Create a combined map of all the line items, preferring newer items over old ones (equality is based on id). | |
| 94 | 96 | val updatedLineItemMap = GuLineItem.asMap(existingItems) ++ GuLineItem.asMap(newItems) | |
@@ -120,7 +122,7 @@ class DfpDataCacheJob(adUnitAgent: AdUnitAgent, | |||
| 120 | 122 | ||
| 121 | 123 | LineItemLoadSummary( | |
| 122 | 124 | validLineItems = updateCachedContent(cachedLineItems.validItems, recentlyModified.validItems), | |
| 123 | - invalidLineItems = updateCachedContent(cachedLineItems.invalidItems, recentlyModified.invalidItems, logging = false) | ||
| 125 | + invalidLineItems = updateCachedContent(cachedLineItems.invalidItems, recentlyModified.invalidItems) | ||
| 124 | 126 | ) | |
| 125 | 127 | } | |
| 126 | 128 | } | |
@@ -142,9 +144,6 @@ class DfpDataCacheJob(adUnitAgent: AdUnitAgent, | |||
| 142 | 144 | Store.putDfpPageSkinAdUnits(stringify(toJson(PageSkinSponsorshipReport(now, | |
| 143 | 145 | pageSkinSponsorships)))) | |
| 144 | 146 | ||
| 145 | - val sponsorshipLineItemIds: List[Long] = data.lineItems.filter(_.lineItemType == Sponsorship).map(_.id).toList | ||
| 146 | - Store.putNonRefreshableLineItemIds(stringify(toJson(sponsorshipLineItemIds))) | ||
| 147 | - | ||
| 148 | 147 | Store.putDfpLineItemsReport(stringify(toJson(LineItemReport(now, data.lineItems, data.invalidLineItems)))) | |
| 149 | 148 | ||
| 150 | 149 | Store.putTopAboveNavSlotTakeovers(stringify(toJson(LineItemReport(now, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,37 +19,37 @@ trait Store extends Logging with Dates { | |||
| 19 | 19 | def getSwitches: Option[String] = S3.get(switchesKey) | |
| 20 | 20 | def getSwitchesWithLastModified: Option[(String, DateTime)] = S3.getWithLastModified(switchesKey) | |
| 21 | 21 | def getSwitchesLastModified: Option[DateTime] = S3.getLastModified(switchesKey) | |
| 22 | - def putSwitches(config: String) { S3.putPublic(switchesKey, config, "text/plain") } | ||
| 22 | + def putSwitches(config: String): Unit = { S3.putPublic(switchesKey, config, "text/plain") } | ||
| 23 | 23 | ||
| 24 | 24 | def getTopStories: Option[String] = S3.get(topStoriesKey) | |
| 25 | - def putTopStories(config: String) { S3.putPublic(topStoriesKey, config, "application/json") } | ||
| 25 | + def putTopStories(config: String): Unit = { S3.putPublic(topStoriesKey, config, "application/json") } | ||
| 26 | 26 | ||
| 27 | - def putInlineMerchandisingSponsorships(keywordsJson: String) { | ||
| 27 | + def putInlineMerchandisingSponsorships(keywordsJson: String): Unit = { | ||
| 28 | 28 | S3.putPublic(dfpInlineMerchandisingTagsDataKey, keywordsJson, defaultJsonEncoding) | |
| 29 | 29 | } | |
| 30 | - def putHighMerchandisingSponsorships(keywordsJson: String) { | ||
| 30 | + def putHighMerchandisingSponsorships(keywordsJson: String): Unit = { | ||
| 31 | 31 | S3.putPublic(dfpHighMerchandisingTagsDataKey, keywordsJson, defaultJsonEncoding) | |
| 32 | 32 | } | |
| 33 | - def putDfpPageSkinAdUnits(adUnitJson: String) { | ||
| 33 | + def putDfpPageSkinAdUnits(adUnitJson: String): Unit = { | ||
| 34 | 34 | S3.putPublic(dfpPageSkinnedAdUnitsKey, adUnitJson, defaultJsonEncoding ) | |
| 35 | 35 | } | |
| 36 | - def putDfpLineItemsReport(everything: String) { | ||
| 36 | + def putDfpLineItemsReport(everything: String): Unit = { | ||
| 37 | 37 | S3.putPublic(dfpLineItemsKey, everything, defaultJsonEncoding) | |
| 38 | 38 | } | |
| 39 | 39 | def putDfpAdUnitList(filename: String, adUnits: String): Unit = { | |
| 40 | 40 | S3.putPublic(filename, adUnits, "text/plain") | |
| 41 | 41 | } | |
| 42 | - def putTopAboveNavSlotTakeovers(takeovers: String) { | ||
| 42 | + def putTopAboveNavSlotTakeovers(takeovers: String): Unit = { | ||
| 43 | 43 | S3.putPublic(topAboveNavSlotTakeoversKey, takeovers, defaultJsonEncoding) | |
| 44 | 44 | } | |
| 45 | - def putDfpTemplateCreatives(creatives: String) { | ||
| 45 | + def putDfpTemplateCreatives(creatives: String): Unit = { | ||
| 46 | 46 | S3.putPublic(dfpTemplateCreativesKey, creatives, defaultJsonEncoding) | |
| 47 | 47 | } | |
| 48 | 48 | def putDfpCustomTargetingKeyValues(keyValues: String): Unit ={ | |
| 49 | 49 | S3.putPublic(dfpCustomTargetingKey, keyValues, defaultJsonEncoding ) | |
| 50 | 50 | } | |
| 51 | - def putNonRefreshableLineItemIds(lineItemIds: String): Unit = { | ||
| 52 | - S3.putPublic(dfpNonRefreshableLineItemIdsKey, lineItemIds, defaultJsonEncoding) | ||
| 51 | + def putNonRefreshableLineItemIds(lineItemIds: Seq[Long]): Unit = { | ||
| 52 | + S3.putPublic(dfpNonRefreshableLineItemIdsKey, Json.stringify(toJson(lineItemIds)), defaultJsonEncoding) | ||
| 53 | 53 | } | |
| 54 | 54 | ||
| 55 | 55 | val now: String = DateTime.now().toHttpDateTimeString | |
| Back | FazBrowse Home | New Git URL |
0 commit comments