Showing tag poster and photos on tag page. Improved campaign fallback logic, fixes wrong ratio selected.
This commit is contained in:
@@ -33,7 +33,7 @@ function curateCampaign(campaign) {
|
||||
};
|
||||
}
|
||||
|
||||
function selectRandomCampaign(primaryCampaigns, entityCampaigns, preferredCampaigns, allCampaigns, options) {
|
||||
function selectRandomCampaign(primaryCampaigns, entityCampaigns, preferredCampaigns) {
|
||||
if (primaryCampaigns.length > 0) {
|
||||
return primaryCampaigns[crypto.randomInt(primaryCampaigns.length)];
|
||||
}
|
||||
@@ -46,14 +46,10 @@ function selectRandomCampaign(primaryCampaigns, entityCampaigns, preferredCampai
|
||||
return preferredCampaigns[crypto.randomInt(preferredCampaigns.length)];
|
||||
}
|
||||
|
||||
if (allCampaigns.length > 0 && options.allowRandomFallback !== false) {
|
||||
return allCampaigns[crypto.randomInt(allCampaigns.length)];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getRandomCampaign(options = {}, context = {}) {
|
||||
export async function getRandomCampaign(options = {}, context = {}, pass = 0) {
|
||||
const campaigns = options.campaigns
|
||||
|| await redis.hGetAll('traxxx:campaigns').then((rawCampaigns) => Object.values(rawCampaigns).map((rawCampaign) => JSON.parse(rawCampaign)));
|
||||
|
||||
@@ -103,6 +99,18 @@ export async function getRandomCampaign(options = {}, context = {}) {
|
||||
|
||||
const randomCampaign = selectRandomCampaign(primaryCampaigns, randomEntityCampaigns, validCampaigns, campaigns, options);
|
||||
|
||||
// no campaign found, gradually widen scope
|
||||
if (!randomCampaign && pass === 0 && options.allowRandomFallback !== false) {
|
||||
return getRandomCampaign({
|
||||
minRatio: options.minRatio,
|
||||
maxRatio: options.maxRatio,
|
||||
}, context, pass + 1);
|
||||
}
|
||||
|
||||
if (!randomCampaign && pass === 1 && options.allowRandomFallback !== false && options.allowRandomRatio) {
|
||||
return getRandomCampaign({}, context, pass + 1);
|
||||
}
|
||||
|
||||
return randomCampaign;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user