@@ -474,6 +474,7 @@ class CozyClient {
474474 }
475475
476476 async _login ( options ) {
477+ console . log ( '🟥 login 1' )
477478 this . emit ( 'beforeLogin' )
478479
479480 this . registerClientOnLinks ( )
@@ -487,18 +488,21 @@ class CozyClient {
487488 }
488489 }
489490
491+ console . log ( '🟥 login 2' )
490492 for ( const link of this . links ) {
491493 if ( link . onLogin ) {
492494 await link . onLogin ( )
493495 }
494496 }
497+ console . log ( '🟥 login 3' )
495498
496499 this . isLogged = true
497500 this . isRevoked = false
498501
499502 if ( this . stackClient instanceof OAuthClient ) {
500503 await this . loadInstanceOptionsFromStack ( )
501504 }
505+ console . log ( '🟥 login 4' )
502506
503507 this . emit ( 'login' )
504508 }
@@ -926,6 +930,8 @@ client.query(Q('io.cozy.bills'))`)
926930 * @returns {Promise<import("./types").QueryResult> }
927931 */
928932 async query ( queryDefinition , { update, executeFromStore, ...options } = { } ) {
933+ console . log ( '⏰query 1' )
934+ const beginPrepare = performance . now ( )
929935 const markQuery = this . performanceApi . mark (
930936 `client.query(${ queryDefinition . doctype } )`
931937 )
@@ -976,21 +982,28 @@ client.query(Q('io.cozy.bills'))`)
976982 executeQueryFromState ( this . store . getState ( ) , queryDefinition )
977983 )
978984 : ( ) => this . requestQuery ( queryDefinition , options )
985+ const endPrepare = performance . now ( )
986+ console . log ( '🍺 CozyClient query prepare took' , ( endPrepare - beginPrepare ) , 'ms' )
987+ const beginExec = performance . now ( )
979988 const response = await this . _promiseCache . exec ( requestFn , ( ) =>
980989 stringify ( queryDefinition )
981990 )
991+ const endExec = performance . now ( )
992+ console . log ( '🍺 CozyClient query exec took' , ( endExec - beginExec ) , 'ms' )
982993
994+ const beginReceive = performance . now ( )
995+ const queryReceivedResult = receiveQueryResult ( queryId , response , {
996+ update,
997+ backgroundFetching
998+ } )
999+ const endReceive = performance . now ( )
1000+ console . log ( '🍺 CozyClient query receiveQueryResult took' , ( endReceive - beginReceive ) , 'ms' )
1001+ const beginDispatch = performance . now ( )
9831002 this . dispatch (
984- receiveQueryResult ( queryId , response , {
985- update,
986- backgroundFetching
987- } )
1003+ queryReceivedResult
9881004 )
989- this . performanceApi . measure ( {
990- markName : markQuery ,
991- measureName : `${ markQuery } success` ,
992- color : 'primary'
993- } )
1005+ const endDispatch = performance . now ( )
1006+ console . log ( '🍺 CozyClient query Dispatch took' , ( endDispatch - beginDispatch ) , 'ms' )
9941007 return response
9951008 } catch ( error ) {
9961009 this . performanceApi . measure ( {
@@ -1025,10 +1038,14 @@ client.query(Q('io.cozy.bills'))`)
10251038 options . as || this . queryIdGenerator . generateId ( queryDefinition )
10261039 const mergedOptions = { ...options , as : queryId }
10271040 try {
1041+ const begin = performance . now ( )
10281042 let resp = await this . query ( queryDefinition , mergedOptions )
1043+ const end = performance . now ( )
1044+ console . log ( '🍺 first query took' , ( end - begin ) , 'ms' )
10291045 const documents = resp . data
10301046
10311047 while ( resp && resp . next ) {
1048+ console . log ( '🍺 while' )
10321049 if ( resp . bookmark ) {
10331050 resp = await this . query (
10341051 queryDefinition . offsetBookmark ( resp . bookmark ) ,
@@ -1046,6 +1063,7 @@ client.query(Q('io.cozy.bills'))`)
10461063 }
10471064 documents . push ( ...resp . data )
10481065 }
1066+ console . log ( '🍺 return docs' )
10491067 return documents
10501068 } catch ( e ) {
10511069 logger . log ( `queryAll error for ${ e . toString ( ) } ` )
@@ -1111,17 +1129,27 @@ client.query(Q('io.cozy.bills'))`)
11111129 * @returns {Promise<import("./types").ClientResponse> }
11121130 */
11131131 async requestQuery ( definition , options ) {
1132+ const begin = performance . now ( )
11141133 const mainResponse = await this . chain . request ( definition , options )
1134+ const end = performance . now ( )
1135+ console . log ( '🛋️ CozyClient chain.request took' , ( end - begin ) , 'ms' )
11151136
1137+ const begin2 = performance . now ( )
11161138 await this . persistVirtualDocuments ( definition , mainResponse . data )
1139+ const end2 = performance . now ( )
1140+ console . log ( '🛋️ CozyClient persistVirtualDocuments took' , ( end2 - begin2 ) , 'ms' )
11171141
11181142 if ( ! definition . includes ) {
1143+ console . log ( '🛋️ CozyClient return no-includes' )
11191144 return mainResponse
11201145 }
1146+ const begin3 = performance . now ( )
11211147 const withIncluded = await this . fetchRelationships (
11221148 mainResponse ,
11231149 this . getIncludesRelationships ( definition )
11241150 )
1151+ const end3 = performance . now ( )
1152+ console . log ( '🛋️ CozyClient fetchRelationships took' , ( end3 - begin3 ) , 'ms' )
11251153 return withIncluded
11261154 }
11271155
@@ -1188,6 +1216,7 @@ client.query(Q('io.cozy.bills'))`)
11881216 }
11891217
11901218 if ( ( ! document . meta ?. rev && ! document . _rev ) || enforce ) {
1219+ console . log ( '🚨🚨🚨🚨 PERSIST' )
11911220 await this . chain . persistCozyData ( document )
11921221 }
11931222 }
@@ -1814,12 +1843,20 @@ instantiation of the client.`
18141843 * @returns {Promise<void> }
18151844 */
18161845 async loadInstanceOptionsFromStack ( ) {
1846+ console . log ( '🔰 loadInstanceOptionsFromStack 1' )
18171847 const results = await Promise . all ( [
18181848 this . query (
18191849 Q ( 'io.cozy.settings' ) . getById ( 'io.cozy.settings.capabilities' )
1820- ) ,
1821- this . query ( Q ( 'io.cozy.settings' ) . getById ( 'io.cozy.settings.instance' ) )
1850+ ) . catch ( error => {
1851+ console . log ( error )
1852+ throw error
1853+ } ) ,
1854+ this . query ( Q ( 'io.cozy.settings' ) . getById ( 'io.cozy.settings.instance' ) ) . catch ( error => {
1855+ console . log ( error )
1856+ throw error
1857+ } )
18221858 ] )
1859+ console . log ( '🔰 loadInstanceOptionsFromStack 2' )
18231860
18241861 const { data : capabilitiesData } = results [ 0 ]
18251862 const { data : instanceData } = results [ 1 ]
0 commit comments