@@ -711,42 +711,43 @@ export class Backend {
711
711
return startEpoch ;
712
712
}
713
713
714
- clearImpressionsForConversionSite ( site : string ) : void {
715
- void site ;
716
- /* TODO
717
- function shouldRemoveImpression(i: Impression): boolean {
714
+ async clearImpressionsForConversionSite ( site : string ) : Promise < void > {
715
+ const db = await this . #getOrCreateDB( ) ;
716
+ const txn = db . transaction ( "impressions" , "readwrite" ) ;
717
+
718
+ for await ( const cursor of txn . store ) {
719
+ const i = cursor . value ;
720
+
718
721
if ( i . intermediarySite === site ) {
719
- return true;
722
+ await cursor . delete ( ) ;
723
+ continue ;
720
724
}
721
725
if ( ! i . conversionSites . has ( site ) ) {
722
- return false ;
726
+ continue ;
723
727
}
724
728
if ( i . conversionSites . size > 1 ) {
725
729
i . conversionSites . delete ( site ) ;
726
- return false;
730
+ await cursor . update ( i ) ;
731
+ continue ;
727
732
}
728
- return true ;
733
+ await cursor . delete ( ) ;
729
734
}
730
-
731
- this.#impressions = this.#impressions.filter(
732
- (i) => !shouldRemoveImpression(i),
733
- );
734
- */
735
735
}
736
736
737
- clearExpiredImpressions ( ) : void {
738
- /* TODO
737
+ async clearExpiredImpressions ( ) : Promise < void > {
738
+ const db = await this . #getOrCreateDB( ) ;
739
+ const txn = db . transaction ( "impressions" , "readwrite" ) ;
740
+
739
741
const now = this . #delegate. now ( ) ;
740
742
741
- this.#impressions = this.#impressions.filter((impression) => {
742
- return (
743
- Temporal.Instant.compare(
744
- now,
745
- impression.timestamp.add(impression.lifetime),
746
- ) < 0
747
- );
748
- });
749
- */
743
+ for await ( const cursor of txn . store . iterate ( ) ) {
744
+ const i = cursor . value ;
745
+ const expiry = i . timestamp . toTemporalInstant ( ) . add ( days ( i . lifetimeDays ) ) ;
746
+
747
+ if ( Temporal . Instant . compare ( now , expiry ) > 0 ) {
748
+ await cursor . delete ( ) ;
749
+ }
750
+ }
750
751
}
751
752
752
753
#fairlyAllocateCredit( credit : number [ ] , value : number ) : number [ ] {
0 commit comments