Merge pull request #212 from emrysal/simplify-counting-use-length-instead
Removed unnecessary DB calls & changes everything to use session.user.id
This commit is contained in:
		
						commit
						e909bc22e7
					
				
					 1 changed files with 3 additions and 18 deletions
				
			
		| 
						 | 
					@ -270,9 +270,6 @@ export async function getServerSideProps(context) {
 | 
				
			||||||
    let credentials = [];
 | 
					    let credentials = [];
 | 
				
			||||||
    let eventTypes = [];
 | 
					    let eventTypes = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let eventTypeCount = 0;
 | 
					 | 
				
			||||||
    let integrationCount = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (session) {
 | 
					    if (session) {
 | 
				
			||||||
        user = await prisma.user.findFirst({
 | 
					        user = await prisma.user.findFirst({
 | 
				
			||||||
            where: {
 | 
					            where: {
 | 
				
			||||||
| 
						 | 
					@ -287,7 +284,7 @@ export async function getServerSideProps(context) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        credentials = await prisma.credential.findMany({
 | 
					        credentials = await prisma.credential.findMany({
 | 
				
			||||||
            where: {
 | 
					            where: {
 | 
				
			||||||
                userId: user.id,
 | 
					                userId: session.user.id,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            select: {
 | 
					            select: {
 | 
				
			||||||
                type: true
 | 
					                type: true
 | 
				
			||||||
| 
						 | 
					@ -296,23 +293,11 @@ export async function getServerSideProps(context) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        eventTypes = await prisma.eventType.findMany({
 | 
					        eventTypes = await prisma.eventType.findMany({
 | 
				
			||||||
            where: {
 | 
					            where: {
 | 
				
			||||||
                userId: user.id,
 | 
					                userId: session.user.id,
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        eventTypeCount = await prisma.eventType.count({
 | 
					 | 
				
			||||||
            where: {
 | 
					 | 
				
			||||||
                userId: session.user.id
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        integrationCount = await prisma.credential.count({
 | 
					 | 
				
			||||||
            where: {
 | 
					 | 
				
			||||||
                userId: session.user.id
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
        props: { user, credentials, eventTypes, eventTypeCount, integrationCount }, // will be passed to the page component as props
 | 
					        props: { user, credentials, eventTypes, eventTypeCount: eventTypes.length, integrationCount: credentials.length }, // will be passed to the page component as props
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in a new issue