#Cache seems not clear when using API Key with node-appwrite

26 messages · Page 1 of 1 (latest)

viral wigeon
#
async function createAdminClient() {
    const client = new AppwriteClient();
  
    client
      .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT as string)
      .setProject(process.env.NEXT_PUBLIC_PROJECT_ID as string)
      .setKey(process.env.AUTH_SESSION_KEY as string);
  
    return {
      account: new Account(client),
      users: new Users(client), 
      teams: new Teams(client),
      functions: new Functions(client),
      databases: new Databases(client),
    };
  };

const createAdminDB = async () => {
    const { databases } = await createAdminClient();
  
    const db = {} as DB;
  
    collections.forEach((col: Collection) => {
      db[col.name as keyof DB] = {
        create: (payload: any, permissions: string[], id = ID.unique()) =>
          databases.createDocument(
            col.dbId,
            col.id,
            id,
            payload,
            permissions
          ),
        update: (id: string, payload: any, permissions: string[]) =>
          databases.updateDocument(
            col.dbId,
            col.id,
            id,
            payload,
            permissions
          ),
        delete: (id: string) => databases.deleteDocument(col.dbId, col.id, id),
        list: (queries = []) =>
          databases.listDocuments(col.dbId, col.id, queries),
        get: (id: string) => databases.getDocument(col.dbId, col.id, id),
      };
    });
  
    return db;
  };
  
  export { createAdminClient, createAdminDB};

and I have logic here to query some data

const db = await createAdminDB();
    const promise: any = await db.clients.list([
      Query.orderDesc("code"),
      Query.limit(1),
    ]);
    console.log(promise)

when I console log. it always get result which is not existed, as I already deleted

#

I try to restart terminal many times

#

also checking on the console web, there is no returned data here

#

I am trying to get the lastest code number from document , to increase it by 1

viral wigeon
#

i need to limit to like 100000 to get all

olive thorn
viral wigeon
#

I am not sure why, if I limit to many like 10000 , it will be okay . but if I limit to 1 , it will be alway returned that document which is deleted and could not find in the console web.

#

is there anything relavent to the API key or not!

olive thorn
viral wigeon
olive thorn
viral wigeon
viral wigeon
#
{
  familyNameKH: 'test',
  givenNameKH: 'test',
  assignedUsers: [ '66a0798a0023cb6c8bd0' ]
}
//
{
  total: 3746,
  documents: [
    {
     
      status: 'Referred',
      code: 4432,
      familyNameEN: '',
      familyNameKH: 'test',
      gender: 'Male',
      givenNameEN: '',
      givenNameKH: 'test',
     
      '$id': '669e63e000046b507791',
      '$createdAt': '2024-07-22T13:51:28.924+00:00',
      '$updatedAt': '2024-07-22T13:51:28.924+00:00',
      '$permissions': [],
      '$databaseId': '644605f0d180522e8906',
      '$collectionId': '645cf88051af5d409148'
    }
  ]
}
last code: 4432
next code: 4433
 POST /clients/add 200 in 596ms
 POST /clients/add 200 in 415ms
 │ GET http://localhost:8../v1/databases/644605f0d1..?queries%5B0%5D=.. 200 in 3ms (cache: HIT)
 │  │ POST http://localhost:8../v1/databases/644605f0d1.. 201 in 306ms (cache: SKIP)
 │  │  │  Cache missed reason: (cache-control: no-cache (hard refresh))
 ✓ Compiled /clients/success/page in 465ms (4322 modules)
 GET /clients/success?_rsc=50qg1 200 in 887ms ```
#

when limit to 1, it always return that code: 4432.

#

no other request seen

olive thorn
viral wigeon
viral wigeon
#

maybe somewhere else, still cachign

#

if there is better approach to get the latest id, it will no issue of nextjs caching

olive thorn
viral wigeon
#

Yes, I also mean the appwrite auto increment id, it was drafted but no plan to release yet , right 👋

#

workaround for now: adding this to server action const _ = cookies();