Skip to content

Commit 52bb122

Browse files
fix(points): batch changeset writes and drop unused auth dep
1 parent 2a38f16 commit 52bb122

4 files changed

Lines changed: 214 additions & 170 deletions

File tree

src/network/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ export class Connection {
641641
// Create the necessary services to fetch points
642642
const idService = new IDService();
643643
const divisions = new DivisionService(this.env.DB);
644-
const pointsService = new PointsService(this.env.DB, idService, divisions, this.auth);
644+
const pointsService = new PointsService(this.env.DB, idService, divisions);
645645

646646
// Fetch all points for this airport
647647
const airportPoints = await pointsService.getAirportPoints(airport);

src/services/id.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import { customAlphabet } from 'nanoid';
2+
23
export class IDService {
3-
private BARS_ID_PREFIX = 'BARS';
4-
private ID_LENGTH = 5;
5-
private ALLOWED_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
4+
private readonly BARS_ID_PREFIX = 'BARS';
5+
private readonly ID_LENGTH = 5;
6+
private readonly ALLOWED_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
7+
private readonly nanoid = customAlphabet(this.ALLOWED_CHARS, this.ID_LENGTH);
8+
69
async generateBarsId(): Promise<string> {
7-
const nanoid = customAlphabet(this.ALLOWED_CHARS, this.ID_LENGTH);
8-
return `${this.BARS_ID_PREFIX}_${nanoid()}`;
10+
const [id] = await this.generateBarsIds(1);
11+
return id;
12+
}
13+
14+
async generateBarsIds(count: number): Promise<string[]> {
15+
if (count <= 0) {
16+
return [];
17+
}
18+
const ids: string[] = [];
19+
for (let i = 0; i < count; i++) {
20+
ids.push(`${this.BARS_ID_PREFIX}_${this.nanoid()}`);
21+
}
22+
return ids;
923
}
1024
}

0 commit comments

Comments
 (0)