| 6 | * Results are cached using React's cache directive. |
| 7 | */ |
| 8 | const generatePartners = async () => { |
| 9 | // For weight sorting, use cached weighted partners |
| 10 | const seconds = 300; // Change every 5 minutes |
| 11 | const seed = Math.floor(Date.now() / (seconds * 1000)); |
| 12 | |
| 13 | // Create weighted array (duplicates based on weight) |
| 14 | const weightedPartners = partners.flatMap(partner => { |
| 15 | const weight = partner.weight ?? 0; |
| 16 | return Array(weight > 0 ? weight : 1).fill(partner); |
| 17 | }); |
| 18 | |
| 19 | // Shuffle and remove duplicates |
| 20 | const shuffled = await shuffle(weightedPartners, seed); |
| 21 | |
| 22 | return Array.from(new Set(shuffled)); |
| 23 | }; |
| 24 | |
| 25 | export default generatePartners; |