mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-27 13:49:10 +02:00
Patch unleash last seen at logic
This commit is contained in:
parent
9ee3be88c2
commit
d0b820b7bc
@ -14,6 +14,26 @@ export interface FeaturesTable {
|
|||||||
environment: string;
|
environment: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const prepareLastSeenInput = (data: LastSeenInput[]) => {
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
const sortedData = data.sort(
|
||||||
|
(a, b) =>
|
||||||
|
a.featureName.localeCompare(b.featureName) ||
|
||||||
|
a.environment.localeCompare(b.environment),
|
||||||
|
);
|
||||||
|
|
||||||
|
const inserts = sortedData.map((item) => {
|
||||||
|
return {
|
||||||
|
feature_name: item.featureName,
|
||||||
|
environment: item.environment,
|
||||||
|
last_seen_at: now,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return inserts;
|
||||||
|
};
|
||||||
|
|
||||||
export default class LastSeenStore implements ILastSeenStore {
|
export default class LastSeenStore implements ILastSeenStore {
|
||||||
private db: Db;
|
private db: Db;
|
||||||
|
|
||||||
@ -32,18 +52,10 @@ export default class LastSeenStore implements ILastSeenStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setLastSeen(data: LastSeenInput[]): Promise<void> {
|
async setLastSeen(data: LastSeenInput[]): Promise<void> {
|
||||||
const now = new Date();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const inserts = data.map((item) => {
|
const inserts = prepareLastSeenInput(data);
|
||||||
return {
|
|
||||||
feature_name: item.featureName,
|
|
||||||
environment: item.environment,
|
|
||||||
last_seen_at: now,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const batchSize = 1000;
|
const batchSize = 500;
|
||||||
|
|
||||||
for (let i = 0; i < inserts.length; i += batchSize) {
|
for (let i = 0; i < inserts.length; i += batchSize) {
|
||||||
const batch = inserts.slice(i, i + batchSize);
|
const batch = inserts.slice(i, i + batchSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user