I'm trying to create 100k products in woocommerce through woocommerce rest api.
But it takes too long to get response from woocommerce. It takes almost 3 minutes per 100 data.
It's normal situation? or Is there any way to solve this issue?
help me please. Thank you in advance.
const CreateToWP = function (data) {
let data_batch = {
create: []
};
data_batch['create'].push(data)
return WooCommerce.post("products/batch", data_batch)
.then((res) => {
console.log(res.data.create.length)
})
Related
I am working on react native application I use firebase as my backend. I fetch data from firebase real time database and render it on the page. But now I want my application to be supported offline.
I used following two functions for rendering.
For listings from database
const loadListings = () => {
let data = [];
listingRef.orderByChild("created_at").on("value", (snapshot) => {
data = [];
snapshot.forEach((listing) => {
data.push(listing.val());
});
cache.store("listings", data.slice(0, 10)); // only stores latest ten listings
setListings(data);
setLoading(false);
});
};
and then use it inside useEffect like.
useEffect(() => {
loadListings();
}, []);
and for listings from cache I used this.
const loadListingsCached = async () => {
let data = await cache.get("listings");
setListings(data);
};
Now I cant put a check inside firs function as effect hook will run only one time and initialy network status is null. its not defined.
how do I achieve this?
by the way link to package I used for detecting connectivity
Edit
I used this hook as second argument to useEffect() but didn't work for me
const netInfo = useNetInfo();
I
What you want to achieve is make the code different depending on what is the network status. In the answer linked by #Rohit there is my answer about how to check the network connectivity with Net Info Package.
What you have to do is make the effect dependant on the status change. You should pass it as a argument to the effect.
const netInfo = useNetInfo();
useEffect(() => {
loadListings();
}, [netInfo]);
This way the code will always run when a network change is detected. I hope this is what you wanted to achive. Please be more specific about you goal and what is the problem. Current questions does not specify if the hook is not working, or the rendering function does not trigger etc.
I want to delete all variations using REST API without passing variation ID. I didn't see any instructions in wooCommerce REST API doc.
I solved it by using an alternative method. The two requests created in this method. First, to call the product than pass the response variation ID's to another batch request, It will delete all the variations but still there is a limit of maximum 100 variation ID's. It won't delete more than 100 variations in a single request.
If anyone knows the better method, please share.
WooCommerce.get("products/794")
.then((response) => {
WooCommerce.post("products/"+response.data.id+"/variations/batch", response.data.variations)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error.response.data);
});
})
.catch((error) => {
console.log(error.response.data);
});
I'm building an ionic app with a SQlite database.
I can already put data in the database, but when I run a simple query to get data, I get really weird feedback.
My simple code
this.databaseService.execQuery('SELECT * FROM timelog WHERE id = ? ORDER BY id DESC',[this.ongoingTimelog.id])
.then((data) => {
console.log(data);
debugger;
});
execQuery(query: string, params?: Array<string | number>): Promise<any> {
return new Promise((resolve, reject) => {
if (!query) {
resolve();
}
this.db.executeSql(query, params)
.then((result: any) => {
resolve(result);
})
});
}
So normally I would suspect (as I get on my pc envoirement) the data to be like data.rows[0].id...
But on my tablet I get the following:
data on phone
Does anybody have any idea why i get something completely different and how I can get the correct data?
Thanks in advance!!
What you see is the javascript wrapper of the SQLite. That wrapper make possible to talk with js and be common for Android and iOS.
Your data is there, the screenshot shows you have one item. To access you need:
this.databaseService.execQuery('SELECT * FROM timelog WHERE id = ? ORDER BY id DESC',[this.ongoingTimelog.id])
.then((data) => {
console.log(data.rows.item(0));
debugger;
});
Needs data.rows.item(0).id instead of data.rows[0].id
Check this sample app it could help. cordova-sqlite-storage-starter-app
Let's say I'm following 10000 users and those users have 1 million followers. Now I want to get their contents.
Right now in my app on average users have 1000 followers, So what I am doing is, when a user post new content, I loop through all his followers and add them to their personalized section using cloud functions.
It works good right now. But what if someone has 1 million followers. What's the best ways to do it..
Function
exports.updateFollowersFeed = functions.database.ref("topics/all/{id}/username/")
.onWrite(event => {
var postid = event.params.id;
var username = event.data.val();
db.ref('topics/all').child(postid).once("value", function(topic) {
db.ref("follows").child(username).child("followers").once("value", function(snap) {
snap.forEach(function(follower) {
db.ref('topics/following').child(follower.key).child(postid).remove();
});
});
});
});
Database Example :
Post
Following Users
Following Contents
Thanks :(
After inserting 29447 entities of a single kind in Google Cloud DataStore I wait about 30 seconds and go and check how many entities are there for that particular kind. The surprising thing is that I notice some of them missing (getCurrentKeys returns a bit less than 29447 entities). When I check after a longer period of time (~1 hour), I can then see that all of the entities are there (getCurrentKeys returns the expected 29447 entities).
The code used to read the number of entities is the following:
const runQuery = (query) => {
return new Promise((resolve, reject) => {
datastore.runQuery(query)
.then(results => {
const entities = results[0];
resolve(entities);
})
.catch(e => reject(e));
});
};
const getCurrentKeys = () => {
const query = datastore.createQuery(KIND)
.select('__key__');
return runQuery(query);
};
async function main() {
const currentKeys = await getCurrentKeys();
console.log(`currentKeys: ${currentKeys.length}`);
}
main();
Any ideas of what could be happening?
Thanks in advance
Non ancestor queries are eventually consistent. It will take a while before all the rows will show up.
This article should explain more:
https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/
After a bit more research I think it might be related to the indexes. I believe the indexes aren't getting updated fast enough by the time I run the query. The entities have many properties, so there are many indexes involved.