Skip to content

Commit

Permalink
lib: Debounce password quality checking during typing
Browse files Browse the repository at this point in the history
The tests type so fast that we end up running enough pwscore processes
in parallel that we run out of file descriptors.
  • Loading branch information
mvollmer committed Nov 8, 2023
1 parent cbc151c commit 0a838b4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/lib/cockpit-components-password.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import cockpit from 'cockpit';
import React, { useState } from 'react';
import { debounce } from 'throttle-debounce';
import { Button } from '@patternfly/react-core/dist/esm/components/Button/index.js';
import { FormGroup, FormHelperText } from "@patternfly/react-core/dist/esm/components/Form/index.js";
import { InputGroup, InputGroupItem } from '@patternfly/react-core/dist/esm/components/InputGroup/index.js';
Expand Down Expand Up @@ -54,6 +55,10 @@ export function password_quality(password, force) {
});
}

const debounced_password_quality = debounce(300, (value, callback) => {
password_quality(value).catch(() => ({ value: 0 })).then(callback);
});

export const PasswordFormFields = ({
password_label, password_confirm_label,
password_label_info,
Expand All @@ -73,14 +78,10 @@ export const PasswordFormFields = ({
change("password", value);

if (value) {
password_quality(value)
.catch(() => {
return { value: 0 };
})
.then(strength => {
setPasswordStrength(strength.value);
setPasswordMessage(strength.message);
});
debounced_password_quality(value, strength => {
setPasswordStrength(strength.value);
setPasswordMessage(strength.message);
});
} else {
setPasswordStrength();
setPasswordMessage("");
Expand Down

0 comments on commit 0a838b4

Please sign in to comment.