magento2 – delete items from the comparison list of api


I am building the rest API to delete compare the list of articles

here is the code that I am using

        / **
* @api
*
* @Return int
* /
public function clearItems () {
$ id = $ this-> userContext-> getUserId ();
$ userType = $ this-> userContext-> getUserType ();
$ this-> collection-> setVisitorId ($ id);
if ($ userType === UserContextInterface :: USER_TYPE_CUSTOMER) {
$ this-> item-> setCustomerId ($ id);
}


$ this-> collection-> clear ();

returns $ id;
}

but it is only deleted from the database and remains in the store. and when you open the comparison list of the store, return to the database
and the returned ID is different from the registered user ID