berlindb / core

All of the required core code
MIT License
255 stars 29 forks source link

Cache does not seem to clear when deleting a single record #59

Closed alexstandiford closed 4 years ago

alexstandiford commented 4 years ago

In my install of Berlin, delete_items appears to delete an item as-expected, however, if that same item is fetched in the same request after it is deleted, the record can still be acquired.


$query = new Query();

$id = $query->add_item();

$event = $query->get_item( $id );

$deleted = $query->delete_item( $id );

$event_after_deletion = $query->get_item( $id );

var_dump( compact( 'event', 'event_after_deletion' ) ); // both event and event_after_deletion return the same value.

In the above example, I would expect $event_after_deletion to be false since the record no-longer exists, however, it returns the value. I'm pretty sure this is because the item is cached, and for some reason the system mistakenly thinks that record is still valid.

alexstandiford commented 4 years ago

I should also mention that if a query is ran against the record ID directly, it works properly:

$query = new Query();

$id = $query->add_item();

$event = $query->get_item( $id );

$deleted = $query->delete_item( $id );

$event_after_deletion = new Query( array( 'id' => $id ) );

var_dump( compact( 'event', 'event_after_deletion' ) ); // works
JJJ commented 4 years ago

Unless we've unintentionally fixed this, I'm unable to replicate, at least inside of Sugar Calendar. Here's my test code, basically the same as yours:

add_action( 'init', function() {

    $events = new \Sugar_Calendar\Event_Query();

    $i = $events->add_item( array(
        'object_id'      => 1,
        'object_type'    => 'jjj',
        'object_subtype' => 'test'
    ) );
    var_dump( $i );

    $e = $events->get_item( $i );
    var_dump( $e );

    $d = $events->delete_item( $i );
    var_dump( $d );

    $eod = $events->get_item( $i );
    var_dump( $eod );

    die;
} );

Output

int 17
object(Sugar_Calendar\Event)[1757]
  public 'id' => string '17' (length=2)
  public 'object_id' => string '1' (length=1)
  public 'object_type' => string 'jjj' (length=3)
  public 'title' => string '' (length=0)
  public 'content' => string '' (length=0)
  public 'status' => string '' (length=0)
  public 'start' => string '0000-00-00 00:00:00' (length=19)
  public 'start_tz' => string '' (length=0)
  public 'end' => string '0000-00-00 00:00:00' (length=19)
  public 'end_tz' => string '' (length=0)
  public 'all_day' => string '0' (length=1)
  public 'recurrence' => string '' (length=0)
  public 'recurrence_interval' => string '0' (length=1)
  public 'recurrence_count' => string '0' (length=1)
  public 'recurrence_end' => string '0000-00-00 00:00:00' (length=19)
  public 'recurrence_end_tz' => string '' (length=0)
  protected 'db_global' => string 'wpdb' (length=4)
  protected 'prefix' => string 'sc' (length=2)
  protected 'last_error' => boolean false
  public 'object_subtype' => string 'test' (length=4)
  public 'date_created' => string '2020-07-28 17:12:49' (length=19)
  public 'date_modified' => string '2020-07-28 17:12:49' (length=19)
  public 'uuid' => string 'urn:uuid:0d3eed74-ee37-4883-911f-99620f5c1ced' (length=45)
int 1
boolean false

Question

What kinds of cache are you seeing this on:

ashleyfae commented 4 years ago

Did this fix it? https://github.com/berlindb/core/issues/27

alexstandiford commented 4 years ago

@ashleyfae you are a saint. I must have somehow missed that change.

This was resolved in #30