Skip to content

Conversation

@pierre
Copy link
Member

@pierre pierre commented Mar 28, 2024

The search key is opaque to the system. Interpret the prefix marker _q=1 as the beginning of an advanced query, allowing to filter on specific fields, e.g.:

_q=1&email=john@acme.com&currency=USD

It is the responsibility of the user to add relevant indexes.

pierre added 3 commits March 28, 2024 18:11
The search key is opaque to the system. Interpret the
prefix marker _q=1 as the beginning of an advanced query,
allowing to filter on specific fields, e.g.:

  _q=1&email=john@acme.com&currency=USD

It is the responsability of the user to add relevant indexes.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Simple solution to work around lack of implicit casting
on PostgreSQL. Good enough for now?

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
This allows us to find all open and paid invoices for instance.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Copy link
Member

@sbrossie sbrossie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

searchQuery = new SearchQuery(SqlOperator.OR);
searchQuery.addSearchClause("currency", SqlOperator.EQ, searchKey);
} else if (searchKey.startsWith(SEARCH_QUERY_MARKER)) {
final Matcher matcher = BALANCE_QUERY_PATTERN.matcher(searchKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the use case that we have to show (return) invoices matching specific balance criteria for the given tenant - and not for a specific account?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the use-case is to filter invoices for that tenant and balance criteria, e.g., show me all unpaid invoices.

There is a branch in the code because it doesn't support additional filtering capabilities: it's either balance filter or any other filter. Cannot do: show me all unpaid invoices in the last month unfortunately. We might be able to do it, it's just a bit hard with the balance specific query...

>>

searchByCurrency(ordering) ::= <<
searchInvoicesByBalance(ordering, comparisonOperator) ::= <<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result(s) we return will match the criteria, but since we just return the columns (fileds), the exact balance will not be returned, is this correct - i.e. balance computation is just used for search criteria and not to populate the objects being returned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

balance computation is just used for search criteria and not to populate the objects being returned

Correct.

since we just return the columns (fileds)

That's a good point, I need to check if the objects are re-hydrated at higher levels of the stack or if I should select more columns here.

Copy link
Member

@sbrossie sbrossie May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just wondering if we could use the amount computed from the underlying invoiceBalanceQuery() so we don't have to rehydrate the invoices as it is very expensive. However, not returning the balance is an issue as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could:

  • Modify InvoiceModelDao to have a balance field. This is set only in this new codepath, when computing the balance in SQL (the balance column from the SQL query should automatically populate it if the getter and setter for balance are added in InvoiceModelDao.
  • Modify DefaultInvoice to have a private balance field. If set during construction of the object (pulled from InvoiceModelDao), getBalance() returns it, otherwise, it goes through the computation like today.

@reshmabidikar Could you give this a try? When doing searches, the invoices will still be shallow, but when searchInvoicesByBalance is called, the balance should be returned. If this work, we could also look at updating the other search queries to do the same?

@pierre
Copy link
Member Author

pierre commented Mar 30, 2024

Note to self: unresolved comments must be addressed before merging.

JOIN invoices inv ON ii.invoice_id = inv.id
LEFT OUTER JOIN tags tg ON ii.invoice_id = tg.object_id
WHERE
ii.type in ('TAX', 'EXTERNAL_CHARGE', 'FIXED', 'USAGE', 'RECURRING', 'ITEM_ADJ', 'REPAIR_ADJ', 'PARENT_SUMMARY', 'CBA_ADJ', 'CREDIT_ADJ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like all the InvoiceItemType are present here, so is this needed?

@sbrossie
Copy link
Member

sbrossie commented Jun 8, 2024

Moving this as 'Ready to review' as we merged #2023

@sbrossie sbrossie marked this pull request as ready for review June 8, 2024 02:54
@sbrossie
Copy link
Member

sbrossie commented Jun 8, 2024

@reshmabidikar Could you create a doc PR to add this new search capability - probably slate doc.

@pierre Do we have a matching kaui task to use this ?

@reshmabidikar
Copy link
Contributor

@reshmabidikar Could you create a doc PR to add this new search capability - probably slate doc.

Noted, will do.

@reshmabidikar reshmabidikar merged commit fe8dd52 into master Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants