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
1=== modified file 'prestashoperpconnect/unit/import_synchronizer.py'
2--- prestashoperpconnect/unit/import_synchronizer.py 2013-07-07 09:46:53 +0000
3+++ prestashoperpconnect/unit/import_synchronizer.py 2013-07-10 09:49:24 +0000
4@@ -156,12 +156,28 @@
5 items to import, then it can either import them directly or delay
6 the import of each item separately.
7 """
8+ page_size = 1000
9
10 def run(self, filters=None):
11 """ Run the synchronization """
12+ if filters is None:
13+ filters = {}
14+ if 'limit' in filters:
15+ self._run_page(filters)
16+ return
17+ page_number = 0
18+ filters['limit'] = '%d,%d' % (page_number * self.page_size, self.page_size)
19+ record_ids = self._run_page(filters)
20+ while len(record_ids) == self.page_size:
21+ page_number += 1
22+ filters['limit'] = '%d,%d' % (page_number * self.page_size, self.page_size)
23+ record_ids = self._run_page(filters)
24+
25+ def _run_page(self, filters):
26 record_ids = self.backend_adapter.search(filters)
27 for record_id in record_ids:
28 self._import_record(record_id)
29+ return record_ids
30
31 def _import_record(self, record):
32 """ Import a record directly or delay the import of the record """