diff --git a/xep-0413.xml b/xep-0413.xml index 6734e6ca..9578e4ec 100644 --- a/xep-0413.xml +++ b/xep-0413.xml @@ -16,8 +16,6 @@ Council XMPP Core - XEP-0060 - XEP-0313 @@ -28,6 +26,23 @@ goffi@goffi.org goffi@jabber.fr + + 0.2 + 2021-08-21 + jp + +

Add a way to discover on which protocols Order-By applies

+

Remove references to SQL (except in implementation notes)

+

Specify that order-by operate on the whole item set and inside a RSM result set

+

Explicitly says that creation and modification dates are set by Pubsub service itself

+

Specify that Clark notation should be used for extensions

+

Add a full example with Pubsub and RSM

+

Add hint for SQL based implementations

+

removed XEP-0060 and XEP-0313 as dependencies, they are mentioned as use cases, but are not mandatory

+

better wording following feedback

+

Namespace bump

+
+
0.1.1 2019-08-20 @@ -49,8 +64,8 @@ -

&xep0060; §6.5.7 allows to retrieve the "most recent items" and &xep0313; state in §3.1 that archives are ordered in "chronological order". While this order is straighforward in general use cases, it is sometimes desirable to use a different order, for instance while using &xep0277;: a spelling mistake correction should not bring an old blog post to the top of retrieved items.

-

This specification allows to explicitly change business logic to retrieve the items in a different order, in a similar way as the "ORDER BY" clause in SQL.

+

&xep0060; §6.5.7 allows to retrieve the "most recent items" and &xep0313; state in §3.1 that archives are ordered in "chronological order". While this order is straightforward in general use cases, it is sometimes desirable to use a different order, for instance while using &xep0277;: a spelling mistake correction should not bring an old blog post to the top of retrieved items.

+

This specification allows to explicitly change business logic to retrieve the items in a different order.

    @@ -64,13 +79,14 @@
    • Date of creation — date when the item has been published ONLY if the item has a new id (i.e. an id which was not already present in the node at the time of publication). If an item reuses an existing id, it overwrites the original item and the date of creation stays the date of creation of the original item.
    • Date of modification — date when the item has been overwritten by a new item of the same id. If the item has never been overwritten, it is equal to the date of creation defined above.
    • +
    • Order Field — data used in the by attribute (e.g. creation or modification)

    Juliet wants to retrieve plays of her favorite writer, William Shakespeare. She wants to retrieve the 3 most recent ones by date of creation.

    -

    To do so, her client do a regular Pubsub request, but adds the <order> element as a children of the <pubsub> element with the "urn:xmpp:order-by:0" namespace and with a 'by' attribute equal to "creation".

    +

    To do so, her client do a regular Pubsub request, but adds the <order> element as a children of the <pubsub> element with the "urn:xmpp:order-by:1" namespace, a by attribute equal to creation and a desc attribute equal to true.

    - + ]]> @@ -128,7 +144,7 @@ ]]> -

    To check that everything is alright, she requests again the last 3 items, but this time by date of modification. To do so, the client proceeds the same way as for date of creation, except that it uses the value "modification" for the 'by' attribute.

    +

    To check that everything is alright, she requests again the last 3 items, but this time by date of modification. To do so, the client proceeds the same way as for date of creation, except that it uses the value modification for the by attribute.

    - + ]]> @@ -173,23 +189,205 @@ - + ]]>

    This way, filters can be used with a specific ordering.

    -

    The ordering can be reversed by using the mechanisms already provided by &xep0059;.

    +

    By default, ordering MUST be done in ascending order. This can be reversed by using the desc boolean attribute, which MAY have a value of either true or 1.

    +
    + +

    This section provides a full example of using Order-By with Pubsub and RSM. For readability, we'll use a node with 4 items that will have following IDs (in order of their creation) A, B, C and D. + Items C has been overwritten after D creation, and item A has been overwritten even later. Thus, when ascending creation order is requested, items are in order A, B, C, D. When ascending modification order is requested, items are in order B, D, C, A.
    + Let's see how this work when Juliet wants to retrieve all items in ascending modification order with RSM using a page size of 2 items: +

    + + + + + + + 2 + + + +]]> + + + + + + + item B + + + + + item D + + + + + B + D + 4 + + + +]]> + +

    + Now Juliet wants to get the second and last page to complete her collection. She does this as usual with RSM, by using the value advertised in <last> element in a <after> element. +

    +

    NOTE: in this example the value used in <last> element is the item ID, but as specified in &xep0059;, an implementation MAY use whatever makes sense to it, the requesting client MUST treat this as an opaque value.

    + + + + + + + 2 + D + + + +]]> + + + + + + + item C + + + + + item A + + + + + C + A + 4 + + + +]]> + +

    + Juliets wonders which are the 2 last items created. To discover this, she request again the node, but this time with a creation order field, and in descending order: +

    + + + + + + + 2 + + + +]]> + + + + + + + item D + + + + + item C + + + + + D + C + 4 + + + +]]> + +

    Now she knows that last created item is D, and the one created before is C.

    +

    Please note that items are in descending order in the whole result set but also inside the RSM page (thus the first item here is D), and that in this order, this request returns the first page, so index is 0 here.

    +

    If Juliet wanted to retrieve the second page of items by descending order of creation, she would do like this:

    + + + + + + + 2 + C + + + +]]> + + + + + + + item B + + + + + item A + + + + + B + A + 4 + + + +]]> +
    -

    This specification can be extended by further XEPs, proposing other kind of ordering in the 'by' attribute (e.g. ordering by filename for a file sharing service). But this is beyond the scope of this XEP, and a client should not assume that other ordering than "creation" and "modification" are available without negociation.

    -

    In a similar way, the semantic described here could be reused in other use cases as for Pubsub or MAM, but this would need to be detailed in a separate specification.

    +

    This specification can be extended by further XEPs, proposing other kind of ordering in the 'by' attribute (e.g. ordering by filename for a file sharing service). But this is beyond the scope of this XEP, and a client should not assume that other ordering than "creation" and "modification" are available without further negotiation. Any new ordering specified in a other XEP SHOULD use the Clark notation to avoid any collision (i.e.: {some_namespace}some_ordering).

    + +

    It is important to note the following points:

    +
      +
    • Order-By affect the order of the whole archive, AND the order of the items inside a RSM result set (i.e. inside a page).
    • +
    • The order of creation or modification is the one set by the Pubsub service itself. Some Pubsub based features like &xep0277; let users specify a creation and modification date ; using them would need item parsing and is NOT what creation and modification is referring to here. A future XEP extending this one could allow to order by user-specified creation or modification date, but this is beyond the scope of this XEP.
    • +
    • The semantic described here can be reused in other use cases as for Pubsub or MAM. If it is the case, the support MUST be advertised using discovery and the namespace covered, as explained in Discovering Support below.
    • +
    • It may be hard to impossible for an implementation to be compliant with features specified at Paging Forwards Through a Result Set in &xep0059;. Notably for some order fields, it may be really difficult to not return duplicate items or to no omit items from pages. People interacting with this XEP must be aware of that, and services implementing this XEP SHOULD try to comply with those features, but MAY not if proven too difficult (those features are not required in RSM anyway as the term MAY is used).
    • +
    +
    -

    If a server supports the "order by" protocol, it MUST advertize it including the "urn:xmpp:order-by:0" discovery feature &NSNOTE; in response to a &xep0030; information request:

    +

    If a server supports the "order by" protocol, it MUST advertize it including the "urn:xmpp:order-by:1" discovery feature &NSNOTE; in response to a &xep0030; information request.
    In addition to the general feature support, an entity MUST indicated on which protocols Order-By can be used, by using the notation urn:xmpp:order-by:1@other_namespace, i.e. a concatenation of:

    +
      +
    • this XEP namespace: urn:xmpp:order-by:1
    • +
    • @
    • +
    • namespace where Order-By is applied
    • +
    +

    So if Order-By is implemented for &xep0060;, the service MUST advertise urn:xmpp:order-by:1@http://jabber.org/protocol/pubsub. If Order-By is implemented for &xep0313;, it is urn:xmpp:order-by:1@urn:xmpp:mam:2.
    + In the following example, the server example.org advertizes Order-By support, and indicates that it is implemented for Pubsub and MAM:

    + … - + + + @@ -213,12 +413,26 @@
    -

    Several ordering elements may be used, this allows to solve next levels of ordering in case of conflicts. In this case, the first ordering (i.e. the top most <order> element) is the main one, the second <order> element is used in case of conflicts, then the next one if a new conflict happens and so on.

    -

    In case of conflicts, if no new <order> element is specified, the item order is not guaranted and is up to the implementation.

    +

    Several ordering elements may be used, this allows to solve next levels of ordering in case of equality. In this case, the first ordering (i.e. the top most <order> element) is the main one, the second <order> element is used in case of equality, then the next one if a new equality happens and so on.

    +

    In case of equality, if no new <order> element is specified, the item order is not guaranteed and is up to the implementation (the implementation MUST keep this order consistent across requests though).

    -

    For implementations based on SQL databases, the "ORDER BY" clause can be used to easily implement this specification. Other kind of databases should have similar mechanisms.

    +

    It may be difficult to find a correct value for <first> and <last> elements of RSM. Indeed, internal ID of items can't be suited for all orderings. For Pubsub service using a SQL database as backend, item ID (XMPP or internal) could be used with a window function such as row_number (supported by major database engines such as PostgreSQL, MariaDB/MySQL or SQLite) over the requested ordering. For instance, on a hypothetical table where items are requested by ascending creation then modification dates after the value ABC (which correspond to XMPP item ID in our case), a request similar to this could be used:

    + (SELECT cte_1.item_index + FROM cte_1 + WHERE cte_1.id = "ABC") + ORDER BY cte_1.item_index ASC + LIMIT 10; +]]> +

    In this example, row_number is decreased by 1 to match RSM index (row_number starts at 1 while RSM index starts at 0), thus the item_index column can be used directly to fill RSM metadata. A Common Table Expression has been used for better readability.

    @@ -234,7 +448,7 @@

    This specification defines the following XML namespace:

      -
    • 'urn:xmpp:order-by:0'
    • +
    • 'urn:xmpp:order-by:1'
    @@ -247,8 +461,8 @@ @@ -260,4 +474,9 @@ ]]>
    + + +

    Thanks to Philipp Hörist, Evgeny xramtsov, Jonas Schäfer¸ and Holger Weiß for their feedback.

    +
    +