@merkl/api 0.10.299 → 0.10.301
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -126,12 +126,22 @@ export declare abstract class RewardRepository {
|
|
126
126
|
};
|
127
127
|
})[]>;
|
128
128
|
static updateClaimed(recipient: string, rewardTokenId: string, campaignId: string, reason: string, amount: string): Promise<Prisma.BatchPayload>;
|
129
|
-
static findManyBreakdownUniques(
|
129
|
+
static findManyBreakdownUniques(uniques: {
|
130
|
+
rewardId: string;
|
131
|
+
campaignId: string;
|
130
132
|
reason: string;
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
}[]): Promise<({
|
134
|
+
reason: string;
|
135
|
+
pending: string;
|
136
|
+
id: number;
|
137
|
+
campaignId: string;
|
138
|
+
amount: string;
|
139
|
+
protocolId: string | null;
|
140
|
+
claimed: string;
|
141
|
+
auxiliaryData1: string | null;
|
142
|
+
auxiliaryData2: string | null;
|
143
|
+
rewardId: string;
|
144
|
+
} | null)[]>;
|
135
145
|
static upsertPendings(rewardTokenId: string, root: string, campaignId: string, toUpdate: PendingEntity[]): Promise<{
|
136
146
|
reason: string;
|
137
147
|
pending: string;
|
@@ -139,24 +139,16 @@ export class RewardRepository {
|
|
139
139
|
},
|
140
140
|
});
|
141
141
|
}
|
142
|
-
static async findManyBreakdownUniques(
|
143
|
-
return await apiDbClient.rewardBreakdown.
|
142
|
+
static async findManyBreakdownUniques(uniques) {
|
143
|
+
return await apiDbClient.$transaction(uniques.map(x => apiDbClient.rewardBreakdown.findUnique({
|
144
144
|
where: {
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
campaignId,
|
150
|
-
},
|
151
|
-
select: {
|
152
|
-
Reward: {
|
153
|
-
select: {
|
154
|
-
recipient: true,
|
155
|
-
},
|
145
|
+
rewardId_campaignId_reason: {
|
146
|
+
rewardId: x.rewardId,
|
147
|
+
campaignId: x.campaignId,
|
148
|
+
reason: x.reason,
|
156
149
|
},
|
157
|
-
reason: true,
|
158
150
|
},
|
159
|
-
});
|
151
|
+
})));
|
160
152
|
}
|
161
153
|
static async upsertPendings(rewardTokenId, root, campaignId, toUpdate) {
|
162
154
|
const users = toUpdate.map(x => x.recipient);
|
@@ -238,23 +238,30 @@ export class RewardService {
|
|
238
238
|
distributionChain: data.distributionChainId,
|
239
239
|
campaignId: data.campaignId,
|
240
240
|
});
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
241
|
+
let totalCreated = 0;
|
242
|
+
let totalUpdated = 0;
|
243
|
+
const uniques = await data.data.map(({ recipient, reason }) => {
|
244
|
+
const rewardId = RewardService.hashId(data.root, recipient, rewardTokenId);
|
245
|
+
return { rewardId, reason, campaignId };
|
246
|
+
});
|
247
|
+
for (let i = 0; i < uniques.length; i += 1000) {
|
248
|
+
const toUpdate = [];
|
249
|
+
const toCreate = [];
|
250
|
+
const exists = await RewardRepository.findManyBreakdownUniques(uniques.slice(i, Math.min(i + 1000, uniques.length)));
|
251
|
+
for (const [pointIndex, point] of data.data.slice(i, Math.min(i + 1000, uniques.length)).entries()) {
|
252
|
+
if (!!exists[pointIndex]) {
|
253
|
+
toUpdate.push(point);
|
254
|
+
}
|
255
|
+
else {
|
256
|
+
toCreate.push(point);
|
257
|
+
}
|
258
|
+
}
|
259
|
+
await RewardRepository.updatePendings(rewardTokenId, data.root, campaignId, toUpdate);
|
260
|
+
await RewardRepository.createPendings(rewardTokenId, data.root, campaignId, toCreate);
|
261
|
+
totalCreated += toCreate.length;
|
262
|
+
totalUpdated += toUpdate.length;
|
263
|
+
}
|
264
|
+
return { created: totalCreated, updated: totalUpdated };
|
258
265
|
}
|
259
266
|
static async countAllchains() {
|
260
267
|
const rewardPerRewardTokenId = await RewardRepository.countRewardPerRewardTokenIdAndRoot();
|