data61 / Mirza

6 stars 2 forks source link

BR: Fix /location/search #364

Open a-stacey opened 5 years ago

a-stacey commented 5 years ago

Currently doesn't work correctly in that it only search within the last result.

I.e. With data that looks like this, only Business2Prefix is ever searched:

devbusinessregistry=# SELECT * FROM location;
             location_id              |         location_gln          | location_biz_id |          last_update          
--------------------------------------+-------------------------------+-----------------+-------------------------------
 bac666e0-38a4-44cc-9a20-01e49466591e | urn:epc:id:sgln:5000001.98765 | Business1Prefix | 2019-01-16 12:12:13.231028+11
 4fb40b6a-cbf2-4a38-b3ed-4ee9c64f9c10 | urn:epc:id:sgln:6000001.12345 | Business2Prefix | 2019-01-16 14:26:34.374487+11
(2 rows)

devbusinessregistry=# SELECT * FROM geo_location;
devbusinessregistry=# SELECT * FROM geo_location;
           geo_location_id            |       geo_location_gln        | geo_location_lat | geo_location_lon | geo_location_address  |          last_update          
--------------------------------------+-------------------------------+------------------+------------------+-----------------------+-------------------------------
 dd02c5c4-ff37-46c8-9c7f-6c3d41c35c01 | urn:epc:id:sgln:5000001.98765 |                1 |                2 | 42 Wallby Way, Sydney | 2019-01-16 12:12:13.231028+11
 e08f981b-6e5b-4e88-8da9-398b4daa1fe8 | urn:epc:id:sgln:6000001.12345 |                3 |                4 | 43 Wallby Way, Sydney | 2019-01-16 14:26:34.374487+11

Workaround: Remove & limit_ 1 from:

searchLocationQuery :: Maybe GS1CompanyPrefix -> Maybe UTCTime -> DB context err [(Location,GeoLocation)]
searchLocationQuery mpfx mafter = pg $ runSelectReturningList $ select $ do

  loc    <- all_ (_locations businessRegistryDB)
  geoloc <- all_ (_geoLocations businessRegistryDB)
              & orderBy_ (desc_ . geoLocation_last_update)
              & limit_ 1

But need to fix this properly and write tests to check for this error in future.

a-stacey commented 5 years ago

@sajidanower23 suggestion on help with debugging this:

anyway, to see the SQL, what you can do is:
- Go to the module `Mirza.Common.Types`
- In the function `runDb`, change `dbf` so that it looks like this:
  ```let dbf =  case e of
            Prod -> B.withDatabase
            _    -> B.withDatabaseDebug putStrLn```
- Compile and run the server
- The SQL will actually appear in stdout then