Merge lp:~arthru/prestashoperpconnect/fix-1199664 into lp:prestashoperpconnect

Proposed by arthru
Status: Merged
Merged at revision: 233
Proposed branch: lp:~arthru/prestashoperpconnect/fix-1199664
Merge into: lp:prestashoperpconnect
Diff against target: 32 lines (+16/-0)
1 file modified
prestashoperpconnect/unit/import_synchronizer.py (+16/-0)
To merge this branch: bzr merge lp:~arthru/prestashoperpconnect/fix-1199664
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review, no test Approve
Sébastien BEAU - http://www.akretion.com Pending
Review via email: mp+173894@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hi,

I fear that it was merged a bit too quick.

Say you have products 1-2500, then 4000-4500, with a hole between the 2 ranges.

If you search from 0 to 1000, then 1001 to 2000, etc. and stops until nothing is found, you will miss the last range of products.

I know that's a very hypothetical issue but it could be prevented as of today.
I don't know too much the Prestashop's API but one way would be to ask the greater ID and loop until reached, is it possible? Otherwise, maybe the last call could be an unlimited query (> last imported) but you could run in the same issue...

review: Needs Fixing (code review, no test)
Revision history for this message
arthru (arthru) wrote :

I don't see the point with the two ranges.

limit=0,1000 will get 1000 elements from the first, and we loop until the response is not composed of 1000 elements.

The limit parameter does not filter for the id less than a number, it is really the 1000 first elements, disregarding if their id is less or more than 1000.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Ok, so that's only wrong assumption from my part, and my dumb ignorance of the Prestashop's API.
Nice to have such an option in the API!

So, LGTM.

review: Approve (code review, no test)
Revision history for this message
arthru (arthru) wrote :

About the merge too quick, I just did a wrong move with bazaar, my bad... (I thought Sébastien merged the branch... but it was just me and my mistake...).

Sorry...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'prestashoperpconnect/unit/import_synchronizer.py'
--- prestashoperpconnect/unit/import_synchronizer.py 2013-07-07 09:46:53 +0000
+++ prestashoperpconnect/unit/import_synchronizer.py 2013-07-10 09:49:24 +0000
@@ -156,12 +156,28 @@
156 items to import, then it can either import them directly or delay156 items to import, then it can either import them directly or delay
157 the import of each item separately.157 the import of each item separately.
158 """158 """
159 page_size = 1000
159160
160 def run(self, filters=None):161 def run(self, filters=None):
161 """ Run the synchronization """162 """ Run the synchronization """
163 if filters is None:
164 filters = {}
165 if 'limit' in filters:
166 self._run_page(filters)
167 return
168 page_number = 0
169 filters['limit'] = '%d,%d' % (page_number * self.page_size, self.page_size)
170 record_ids = self._run_page(filters)
171 while len(record_ids) == self.page_size:
172 page_number += 1
173 filters['limit'] = '%d,%d' % (page_number * self.page_size, self.page_size)
174 record_ids = self._run_page(filters)
175
176 def _run_page(self, filters):
162 record_ids = self.backend_adapter.search(filters)177 record_ids = self.backend_adapter.search(filters)
163 for record_id in record_ids:178 for record_id in record_ids:
164 self._import_record(record_id)179 self._import_record(record_id)
180 return record_ids
165181
166 def _import_record(self, record):182 def _import_record(self, record):
167 """ Import a record directly or delay the import of the record """183 """ Import a record directly or delay the import of the record """