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