<commit_before>import {
	all,
	call,
	put,
	select,
	takeLatest,
	race
} from 'redux-saga/effects'
import { delay } from 'redux-saga'
import logger from '../util/logger'
import { SID_CARD_TIMEOUT, SID_API_TTL } from '../AppSettings'
import StudentIDService from '../services/studentIDService'


// const getStudentProfile = state => (state.studentProfile)
const getUserData = state => (state.user)
const getStudentProfile =  state => (state.studentProfile)

function* updateStudentProfile() {
	const { lastUpdated, data } = yield select(getStudentProfile)
	const { isLoggedIn, profile } = yield select(getUserData)

	const nowTime = new Date().getTime()
	const timeDiff = nowTime - lastUpdated
	const sidTTl = SID_API_TTL

	if (timeDiff < sidTTl && data) {
		// Do nothing, no need to fetch new data
	} else if (isLoggedIn && profile.classifications.student) {
		put({ type: 'SHOW_CARD', id: 'studentId' })
		const fetchArray = [
			put({ type: 'GET_STUDENT_BARCODE_REQUEST' }),
			put({ type: 'GET_STUDENT_PROFILE_REQUEST' }),
			put({ type: 'GET_STUDENT_PHOTO_REQUEST' }),
			put({ type: 'GET_STUDENT_NAME_REQUEST' }),
		]
		yield all(fetchArray)
	}
}

function* fetchStudentBarcode() {
	try {
		const { response, timeout } = yield race({
			response: call(StudentIDService.FetchStudentBarcode),
			timeout: call(delay, SID_CARD_TIMEOUT)<commit_msg>fix student ID card showing up on preferences without logging in (4)<commit_after>import {
	all,
	call,
	put,
	select,
	takeLatest,
	race
} from 'redux-saga/effects'
import { delay } from 'redux-saga'
import logger from '../util/logger'
import { SID_CARD_TIMEOUT, SID_API_TTL } from '../AppSettings'
import StudentIDService from '../services/studentIDService'


// const getStudentProfile = state => (state.studentProfile)
const getUserData = state => (state.user)
const getStudentProfile =  state => (state.studentProfile)

function* updateStudentProfile() {
	const { lastUpdated } = yield select(getStudentProfile)
	const { isLoggedIn, profile } = yield select(getUserData)

	const nowTime = new Date().getTime()
	const timeDiff = nowTime - lastUpdated

	if (timeDiff < SID_API_TTL) {
		// Do nothing, no need to fetch new data
	} else if (isLoggedIn && profile.classifications.student) {
		yield put({ type: 'SHOW_CARD', id: 'studentId' })
		const fetchArray = [
			put({ type: 'GET_STUDENT_BARCODE_REQUEST' }),
			put({ type: 'GET_STUDENT_PROFILE_REQUEST' }),
			put({ type: 'GET_STUDENT_PHOTO_REQUEST' }),
			put({ type: 'GET_STUDENT_NAME_REQUEST' }),
		]
		yield all(fetchArray)
	}
}

function* fetchStudentBarcode() {
	try {
		const { response, timeout } = yield race({
			response: call(StudentIDService.FetchStudentBarcode),
			timeout: call(delay, SID_CARD_TIMEOUT)
{'fraction_non_alphanumeric': 0.12472487160674982, 'fraction_numerical': 0.00036683785766691124, 'mean_word_length': 4.765327695560254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1058636', 'n_tokens_mistral': 958, 'n_tokens_neox': 918, 'n_words': 228}