Commit 6beca2f2 authored by Cédric Moreau's avatar Cédric Moreau

[mod] `members2` => allow to filter by UID or PUBKEY, **no more full scan**

parent 06f26663
......@@ -68,4 +68,6 @@ MEMBER_FILTER search a member
EXPIRE_TIME expiration datetime
RANDOM_LIST Draw lots
RANDOM_LIST_END membres (max. 100)
MEMBERS members
\ No newline at end of file
MEMBERS members
UID_OR_PUB_LIST Whose pseudo or key contains
UID_OR_PUB_LIST_END (3 chars. min.)
......@@ -68,4 +68,6 @@ MEMBER_FILTER rechercher un membre
EXPIRE_TIME date et heure d'expiration
RANDOM_LIST Tirer au sort
RANDOM_LIST_END membres (max. 100)
MEMBERS membres
\ No newline at end of file
MEMBERS membres
UID_OR_PUB_LIST Dont le pseudo ou la clé contient
UID_OR_PUB_LIST_END (3 car. min.)
......@@ -69,6 +69,8 @@ module.exports = async (req: any, res: any, next: any) => {
var pendingSigs = req.query.pendingSigs || "no"; // Valeur par défaut
var centrality = req.query.centrality || "no"; // Valeur par défaut
var format = req.query.format || 'HTML'; // Valeur par défaut
let uidOrPubList = req.query.uidOrPubList === 'yes';
let uidOrPubValue = req.query.uidOrPubValue;
let nextYn = (req.query.nextYn=="yes") ? "yes":"no";
let randomList = req.query.randomList === 'no' ? 'no' : 'yes';
let numberOfRandomMembers = parseInt(req.query.randomCounts) || MonitConstants.MEMBERS_VIEW.DEFAULT_MEMBERS_RANDOM_NUMBER
......@@ -86,7 +88,17 @@ module.exports = async (req: any, res: any, next: any) => {
let lastUpgradeTimeDatas = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.INIT);
let dSenCache = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_D_SEN);
if (lastUpgradeTimeDatas > 0 && dSenCache > dSen) { previousNextYn == "yes"; }
// Recherche par pseudo/pubkey
if (uidOrPubList) {
// UID/PUB > random
randomList = 'no'
if (!uidOrPubValue || uidOrPubValue.length < 3) {
// Recherche trop large
uidOrPubList = false
randomList = 'yes' // A la place
}
}
// Alimenter wotb avec la toile actuelle
const wotbInstance = duniterServer.dal.wotb;
......@@ -94,7 +106,8 @@ module.exports = async (req: any, res: any, next: any) => {
let reinitCache = (Math.floor(Date.now() / 1000) > (membersLastUptime + MonitConstants.MIN_MEMBERS_UPDATE_FREQ));
// Si changement de conditions, alors forcer le rechargement du cache s'il n'est pas vérouillé, sinon forcer les conditions à celles en mémoire
if (previousMode != mode || previousCentrality != centrality || previousNextYn != nextYn || previousRandomList != randomList || numberOfRandomMembers != previousRandomCounts)
// Si recherche par UID ou pubkey => recharger systématiquement
if (uidOrPubList || previousMode != mode || previousCentrality != centrality || previousNextYn != nextYn || previousRandomList != randomList || numberOfRandomMembers != previousRandomCounts)
{
if (!lockMembers)
{
......@@ -184,6 +197,12 @@ module.exports = async (req: any, res: any, next: any) => {
}
membersList = randomMembers
}
else if (uidOrPubList) {
// Rerchercher les membres qui matchent par l'UID ou la pubkey
membersList = membersList.filter(m => {
return m.uid.toLocaleLowerCase().includes(uidOrPubValue) || m.pub.toLocaleLowerCase().includes(uidOrPubValue)
})
}
// Récupérer pour chaque identité, le numéro du block d'écriture du dernier membership
// Ainsi que la première ou dernière certification
......@@ -590,7 +609,9 @@ module.exports = async (req: any, res: any, next: any) => {
// get parameters
days, mode, sort_by, order,
pendingSigs, centrality, nextYn,
numberOfRandomMembers, randomList,
numberOfRandomMembers: numberOfRandomMembers, randomList,
// Formulaire de recherche par UID ou PUB
uidOrPubList, uidOrPubValue,
// page data
currentBlockchainTimestamp,
......
......@@ -49,6 +49,8 @@ ${printMenu(MENU_LANG, help, "MEMBERS")}
<input type="checkbox" name="nextYn" value="yes" ${nextYn == 'yes' ? 'checked' : ''}> ${LANG["NEXT_YN"]}<br>
<input type="checkbox" name="randomList" value="yes" ${randomList == 'yes' ? 'checked' : ''}> ${LANG["RANDOM_LIST"]}
<input type="number" name="randomCounts" value="${numberOfRandomMembers}"/> ${LANG["RANDOM_LIST_END"]}.<br>
<input type="checkbox" name="uidOrPubList" value="yes" ${uidOrPubList ? 'checked' : ''}> ${LANG["UID_OR_PUB_LIST"]}
<input type="search" name="uidOrPubValue" value="${uidOrPubValue || ''}"/> ${LANG["UID_OR_PUB_LIST_END"]}.<br>
<hr>
<!-- Afficher la légende et l'aide -->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment