Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a 4-minute delay between calling the function and processing the db.transaction. #583

Open
kiflay opened this issue Oct 12, 2024 · 0 comments

Comments

@kiflay
Copy link

kiflay commented Oct 12, 2024

I’m using SQLite for a prepared database, but I’m encountering an issue where querying even 70 rows of data takes about 4 minutes.

here is my code for querying the database
`

  export const getNouns = async query => {
  var nouns = [];
  var message = '';
  console.log('Query home:' + new Date(), query);
  await db.transaction(
    tx => {
      console.log('Query home trans:' + new Date(), query);
      tx.executeSql(
        query,
        [],
        (tx, results) => {
          console.log('Query home result:' + new Date(), results);
          for (let i = 0; i < results.rows.length; ++i) {
            nouns.push(results.rows.item(i));
          }
          return nouns;
        },
        error => {
          console.log('error while executing the query: Execute: ', error);
          message = `error while executing the query: Execute: ${error}`;
        },
      );
    },
    error => {
      console.log('error while executing the query: Transaction:', error);
      message = `error while executing the query: Execute: ${error}`;
    },
  );
  return nouns;
};

here is how i call the function to get the data

    ` const MainHome = () => {
      var nouns = [];
      useEffect(() => {
        async function fetchData() {
          nouns = await getNouns('SELECT Id, Text, User, CreatedAt FROM Messages');
        }
        fetchData();
      });

      console.log(`Messages Home page:` + new Date(), nouns);
      return (
        <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
          <Text>Main Home Screen </Text>
          {nouns.map(item => {
            return (
              <View key={item.Id}>
                <Text> {item.User}</Text>
              </View>
            );
          })}
        </View>
      );
    };

here is the screenshot of the time taken to call the function and process it
image

I was wondering if there is any way to quickly process the data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant