fixed some of the loading bugs with shifts so that the map can load faster.
This commit is contained in:
@@ -27,7 +27,7 @@ class ShiftsController {
|
||||
// If signups sheet is configured, calculate current volunteer counts
|
||||
if (config.nocodb.shiftSignupsSheetId) {
|
||||
try {
|
||||
const signupsResponse = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const signupsResponse = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignups = signupsResponse.list || [];
|
||||
|
||||
// Update each shift with calculated volunteer count
|
||||
@@ -78,7 +78,7 @@ class ShiftsController {
|
||||
}
|
||||
|
||||
// Load all signups and filter in JavaScript
|
||||
const allSignups = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId, {
|
||||
const allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId, {
|
||||
sort: '-Signup Date'
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@ class ShiftsController {
|
||||
let currentVolunteers = 0;
|
||||
let allSignups = { list: [] }; // Initialize with empty list
|
||||
if (config.nocodb.shiftSignupsSheetId) {
|
||||
allSignups = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
const confirmedSignups = (allSignups.list || []).filter(signup =>
|
||||
signup['Shift ID'] === parseInt(shiftId) && signup.Status === 'Confirmed'
|
||||
);
|
||||
@@ -238,7 +238,7 @@ class ShiftsController {
|
||||
logger.info(`User ${userEmail} attempting to cancel signup for shift ${shiftId}`);
|
||||
|
||||
// Find the signup
|
||||
const allSignups = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
const signup = (allSignups.list || []).find(s => {
|
||||
return s['Shift ID'] === parseInt(shiftId) &&
|
||||
s['User Email'] === userEmail &&
|
||||
@@ -258,7 +258,7 @@ class ShiftsController {
|
||||
});
|
||||
|
||||
// Calculate current volunteers dynamically after cancellation
|
||||
const allSignupsAfter = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignupsAfter = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
const confirmedSignupsAfter = (allSignupsAfter.list || []).filter(s =>
|
||||
s['Shift ID'] === parseInt(shiftId) && s.Status === 'Confirmed'
|
||||
);
|
||||
@@ -380,7 +380,7 @@ class ShiftsController {
|
||||
if (config.nocodb.shiftSignupsSheetId) {
|
||||
try {
|
||||
// Get all signups and filter in JavaScript to avoid NocoDB query issues
|
||||
const allSignups = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
|
||||
// Filter for confirmed signups for this shift
|
||||
const signupsToCancel = (allSignups.list || []).filter(signup =>
|
||||
@@ -455,88 +455,47 @@ class ShiftsController {
|
||||
}
|
||||
}
|
||||
|
||||
logger.info('Loaded shifts:', shifts);
|
||||
logger.info('Loaded shifts:', shifts.list?.length || 0, 'records');
|
||||
|
||||
// Only try to get signups if the signups sheet is configured
|
||||
if (config.nocodb.shiftSignupsSheetId) {
|
||||
// Get signup counts for each shift
|
||||
for (const shift of shifts.list || []) {
|
||||
try {
|
||||
// Use getAllPaginated to ensure we get ALL signup records
|
||||
const signups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
|
||||
// Debug logging for shift ID 4 (Sunday Evening Canvass Central Location)
|
||||
if (shift.ID === 4) {
|
||||
// Show ALL signups first
|
||||
logger.info(`Debug: Shift ID 4 - All signups from NocoDB (total ${signups.list?.length || 0})`);
|
||||
|
||||
// Show only signups for shift ID 4 (before status filter)
|
||||
const shift4Signups = (signups.list || []).filter(signup =>
|
||||
parseInt(signup['Shift ID']) === 4
|
||||
);
|
||||
logger.info(`Debug: Shift ID 4 - All signups for this shift (${shift4Signups.length}):`);
|
||||
shift4Signups.forEach((s, index) => {
|
||||
logger.info(` Signup ${index + 1}:`, {
|
||||
ID: s.ID,
|
||||
'Shift ID': s['Shift ID'],
|
||||
'Status': `"${s.Status}"`,
|
||||
'Status Length': s.Status ? s.Status.length : 'null',
|
||||
'Status Chars': s.Status ? Array.from(s.Status).map(c => c.charCodeAt(0)) : 'null',
|
||||
'User Email': s['User Email'],
|
||||
'User Name': s['User Name'],
|
||||
'Signup Date': s['Signup Date']
|
||||
});
|
||||
});
|
||||
try {
|
||||
// Get ALL signups once instead of querying for each shift
|
||||
logger.info('Loading all signups once for performance optimization...');
|
||||
const allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
|
||||
logger.info(`Loaded ${allSignups.list?.length || 0} total signups from database`);
|
||||
|
||||
// Group signups by shift ID for efficient processing
|
||||
const signupsByShift = {};
|
||||
(allSignups.list || []).forEach(signup => {
|
||||
const shiftId = parseInt(signup['Shift ID']);
|
||||
if (!signupsByShift[shiftId]) {
|
||||
signupsByShift[shiftId] = [];
|
||||
}
|
||||
|
||||
// Filter signups for this shift manually with more robust checking
|
||||
const shiftSignups = (signups.list || []).filter(signup => {
|
||||
// Handle type conversion for Shift ID comparison
|
||||
const signupShiftId = parseInt(signup['Shift ID']);
|
||||
const currentShiftId = parseInt(shift.ID);
|
||||
|
||||
// Only process signups for this specific shift
|
||||
if (signupShiftId !== currentShiftId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// For shift ID 4, let's check all possible status variations
|
||||
if (currentShiftId === 4) {
|
||||
const signupStatus = (signup.Status || '').toString().trim();
|
||||
const isConfirmed = signupStatus.toLowerCase() === 'confirmed';
|
||||
|
||||
logger.info(`Debug: Shift ID 4 - Checking signup:`, {
|
||||
'User Email': signup['User Email'],
|
||||
'Status Raw': `"${signup.Status}"`,
|
||||
'Status Trimmed': `"${signupStatus}"`,
|
||||
'Status Lower': `"${signupStatus.toLowerCase()}"`,
|
||||
'Is Confirmed': isConfirmed
|
||||
});
|
||||
|
||||
return isConfirmed;
|
||||
}
|
||||
|
||||
// Handle multiple possible "confirmed" status values for other shifts
|
||||
const signupStatus = (signup.Status || '').toString().toLowerCase().trim();
|
||||
const isConfirmed = signupStatus === 'confirmed' || signupStatus === 'active' ||
|
||||
(signupStatus === '' && signup['User Email']); // Include records with empty status if they have an email
|
||||
|
||||
return isConfirmed;
|
||||
});
|
||||
// Only include confirmed signups
|
||||
const signupStatus = (signup.Status || '').toString().toLowerCase().trim();
|
||||
const isConfirmed = signupStatus === 'confirmed' || signupStatus === 'active' ||
|
||||
(signupStatus === '' && signup['User Email']); // Include records with empty status if they have an email
|
||||
|
||||
// Debug logging for shift ID 4
|
||||
if (shift.ID === 4) {
|
||||
logger.info(`Debug: Shift ID 4 - Filtered signups (${shiftSignups.length}):`, shiftSignups.map(s => ({
|
||||
'Shift ID': s['Shift ID'],
|
||||
'Status': s.Status,
|
||||
'User Email': s['User Email'],
|
||||
'User Name': s['User Name']
|
||||
})));
|
||||
if (isConfirmed) {
|
||||
signupsByShift[shiftId].push(signup);
|
||||
}
|
||||
|
||||
shift.signups = shiftSignups;
|
||||
} catch (signupError) {
|
||||
logger.error(`Error loading signups for shift ${shift.ID}:`, signupError);
|
||||
});
|
||||
|
||||
// Assign signups to each shift
|
||||
for (const shift of shifts.list || []) {
|
||||
const shiftId = parseInt(shift.ID);
|
||||
shift.signups = signupsByShift[shiftId] || [];
|
||||
}
|
||||
|
||||
logger.info(`Processed signups for ${Object.keys(signupsByShift).length} shifts`);
|
||||
|
||||
} catch (signupError) {
|
||||
logger.error('Error loading signups:', signupError);
|
||||
// Set empty signups for all shifts on error
|
||||
for (const shift of shifts.list || []) {
|
||||
shift.signups = [];
|
||||
}
|
||||
}
|
||||
@@ -601,7 +560,7 @@ class ShiftsController {
|
||||
}
|
||||
|
||||
// Check if user is already signed up
|
||||
const allSignups = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
const existingSignup = (allSignups.list || []).find(signup => {
|
||||
return signup['Shift ID'] === parseInt(shiftId) &&
|
||||
signup['User Email'] === userEmail &&
|
||||
@@ -695,7 +654,7 @@ class ShiftsController {
|
||||
});
|
||||
|
||||
// Update shift volunteer count
|
||||
const allSignups = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
const confirmedSignups = (allSignups.list || []).filter(s =>
|
||||
s['Shift ID'] === parseInt(shiftId) && s.Status === 'Confirmed'
|
||||
);
|
||||
@@ -743,7 +702,7 @@ class ShiftsController {
|
||||
}
|
||||
|
||||
// Get all confirmed signups for this shift
|
||||
const allSignups = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignups = await nocodbService.getAllPaginated(config.nocodb.shiftSignupsSheetId);
|
||||
const shiftSignups = (allSignups.list || []).filter(signup =>
|
||||
signup['Shift ID'] === parseInt(shiftId) && signup.Status === 'Confirmed'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user