admin管理员组文章数量:1335814
In working with a third-party API, I need to store some state information to help track a process. I'm wondering where and how I should store it.
Specifically, I have a multi-page Gravity Form, and using the hooks they provide, I'm submitting a POST request to an API once the first page is filled out, getting back a unique ID, and then submitting the fields from the second page to the API with a PATCH request. (There are good reasons for this seemingly complex flow.)
I have a unique ID for the form submission, and a unique ID for the API record that's created and then needs to be updated. What I'm looking for is the best way to connect that information in the database so that when the second page of the form is completed, I know which API record should be updated.
I've considered using the Transients API, since this is by definition a very temporary storage need, but since the data is not guaranteed to be there when I need it, I don't think it will work.
I'm leaning towards using an associative array (with the unique form ID as the key) with the Options API. My concern: if I have dozens or even hundreds of people filling out this form at the same time, is there a risk of race conditions or similar issues in writing to one option? Should I break this out into one option per form submission? Or create a separate table similar to the postmeta table?
Or am I overthinking this, and a single array in an option will be just fine?
In working with a third-party API, I need to store some state information to help track a process. I'm wondering where and how I should store it.
Specifically, I have a multi-page Gravity Form, and using the hooks they provide, I'm submitting a POST request to an API once the first page is filled out, getting back a unique ID, and then submitting the fields from the second page to the API with a PATCH request. (There are good reasons for this seemingly complex flow.)
I have a unique ID for the form submission, and a unique ID for the API record that's created and then needs to be updated. What I'm looking for is the best way to connect that information in the database so that when the second page of the form is completed, I know which API record should be updated.
I've considered using the Transients API, since this is by definition a very temporary storage need, but since the data is not guaranteed to be there when I need it, I don't think it will work.
I'm leaning towards using an associative array (with the unique form ID as the key) with the Options API. My concern: if I have dozens or even hundreds of people filling out this form at the same time, is there a risk of race conditions or similar issues in writing to one option? Should I break this out into one option per form submission? Or create a separate table similar to the postmeta table?
Or am I overthinking this, and a single array in an option will be just fine?
Share Improve this question asked May 21, 2020 at 16:24 Sarah LewisSarah Lewis 2251 gold badge4 silver badges12 bronze badges1 Answer
Reset to default 0I ran a JMeter load test with one hundred simultaneous visitors to see if it is practical to write an array to the wp_options table via the Options API, knowing the array needs to be updated for every visit.
This test confirmed that only a portion of the database updates happened in the way they need to, without overwriting other versions of the array. I expect the exact proportion of failures will vary with load, but since I need my state information to be reliably available, any failures make this a non-starter for me.
My plan going forward is to create a custom table similar to the postmeta table, but tying my unique form ID and unique API ID together rather than a post.
本文标签:
版权声明:本文标题:options - What structure and database storage method should I use for temporary storage that may be written concurrently? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742399699a2467635.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论