-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from leblowl/memoize-performance
Improve performance of memoized validator functions.
- Loading branch information
Showing
4 changed files
with
50 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { describe, bench } from 'vitest' | ||
import * as Auth from '../index.js' | ||
|
||
describe('auth', () => { | ||
bench('a new member joining', () => { | ||
const founderUsername = 'founder' | ||
const founderContext = { | ||
user: Auth.createUser(founderUsername, founderUsername), | ||
device: Auth.createDevice({ userId: founderUsername, deviceName: 'laptop' }), | ||
} | ||
const teamName = 'Test' | ||
const team = Auth.createTeam(teamName, founderContext) | ||
|
||
// Add 100 test users | ||
|
||
const usernames = Array.from({ length: 100 }, (_, i) => `user-${i}`) | ||
|
||
for (const username of usernames) { | ||
const user = Auth.createUser(username, username) | ||
const device = Auth.createDevice({ userId: username, deviceName: 'dev/' + username }) | ||
team.addForTesting(user, [], Auth.redactDevice(device)) | ||
} | ||
|
||
// Invite new user and have them join | ||
|
||
const { seed } = team.inviteMember({ maxUses: 1000 }) | ||
|
||
const username = 'new-user' | ||
const user = Auth.createUser(username, username) | ||
const device = Auth.createDevice({ userId: username, deviceName: 'laptop' }) | ||
const proofOfInvitation = Auth.generateProof(seed) | ||
|
||
team.admitMember(proofOfInvitation, Auth.redactKeys(user.keys), user.userName) | ||
|
||
const serializedGraph = team.save() | ||
const teamKeyring = team.teamKeyring() | ||
const team2 = new Auth.Team({ source: serializedGraph, context: { user, device }, teamKeyring }) | ||
|
||
team2.join(teamKeyring) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters