Skip to content

Changing an annotation gets added as a new annotation #5

@davidfor

Description

@davidfor

While testing for the Kobo devices, fetched the annotations, then I changed one on the device and did another fetch. The changed annotation was added as a new annotation in the column. Doing a third fetch, removed the original version and left only the second version.

After the first fetch, I had:

  <div class="annotation" genre=""
  hash="fe72eed43f4dedfcd9c003e1eafb0afd" location_sort="000200"
  reader="KoboTouch" style="margin:0 0 0.5em 0">
    <table cellpadding="0" width="100%"
    style="background-color:LightGray;color:black;font-size:80%;font-weight:bold;margin:0;"
    color="Gray">
      <tbody>
        <tr>
          <td class="location" style="text-align:left">Extra
          Chapters</td>
          <td class="timestamp" uts="1387924396.0"
          style="text-align:right">25/12/2013 09:33:16</td>
        </tr>
      </tbody>
    </table>
    <p class="highlight" style="margin:0;text-indent:0.5em;">Extra
    Chapters</p>
    <p class="note"
    style="font-size:90%;font-style:italic;margin:0;">0</p>
  </div>

After adding text to the annotation and fetching again, I have:

  <div class="annotation" genre=""
  hash="fe72eed43f4dedfcd9c003e1eafb0afd" location_sort="000200"
  reader="KoboTouch" style="margin:0 0 0.5em 0">
    <table cellpadding="0" width="100%"
    style="background-color:LightGray;color:black;font-size:80%;font-weight:bold;margin:0;"
    color="Gray">
      <tbody>
        <tr>
          <td class="location" style="text-align:left">Extra
          Chapters</td>
          <td class="timestamp" uts="1387924396.0"
          style="text-align:right">25/12/2013 09:33:16</td>
        </tr>
      </tbody>
    </table>
    <p class="highlight" style="margin:0;text-indent:0.5em;">Extra
    Chapters</p>
    <p class="highlight" style="margin:0;text-indent:0.5em;"></p>
    <p class="note"
    style="font-size:90%;font-style:italic;margin:0;">0</p>
    <p class="note"
    style="font-size:90%;font-style:italic;margin:0;"></p>
  </div>
  <div class="annotation" genre=""
  hash="8f8b5c8c247f7470afbd0ecc58ac74a1" location_sort="000200"
  reader="KoboTouch" style="margin:0 0 0.5em 0">
    <table cellpadding="0" width="100%"
    style="background-color:LightGray;color:black;font-size:80%;font-weight:bold;margin:0;"
    color="Gray">
      <tbody>
        <tr>
          <td class="location" style="text-align:left">Extra
          Chapters</td>
          <td class="timestamp" uts="1388271595.0"
          style="text-align:right">29/12/2013 09:59:55</td>
        </tr>
      </tbody>
    </table>
    <p class="highlight" style="margin:0;text-indent:0.5em;">Extra
    Chapters</p>
    <p class="note"
    style="font-size:90%;font-style:italic;margin:0;">0 - update
    1</p>
  </div>

On the third fetch, after disconnecting the device and restarting calibre, I get:

  <div class="annotation" genre=""
  hash="8f8b5c8c247f7470afbd0ecc58ac74a1" location_sort="000200"
  reader="KoboTouch" style="margin:0 0 0.5em 0">
    <table cellpadding="0" width="100%"
    style="background-color:LightGray;color:black;font-size:80%;font-weight:bold;margin:0;"
    color="Gray">
      <tbody>
        <tr>
          <td class="location" style="text-align:left">Extra
          Chapters</td>
          <td class="timestamp" uts="1388271595.0"
          style="text-align:right">29/12/2013 09:59:55</td>
        </tr>
      </tbody>
    </table>
    <p class="highlight" style="margin:0;text-indent:0.5em;">Extra
    Chapters</p>
    <p class="note"
    style="font-size:90%;font-style:italic;margin:0;">0 - update
    1</p>
  </div>

From looking at the code, the issue is the hash.

The method "merge_annotations", gets the old version of the annotations and the new version. It then gets a list of the hashes from both versions. Then it works out what hashes are in the new annotations but not the old. The annotations for these hashes are then added to old annotations.

The problem with this is the way the hashes are calculated. They are produced from the selected text and the annotation text. Changing one of these on the device will produce a new hash value. Hence they won't match and the changed annotation will appear as a new annotation.

I would suggest using the annotation_id. That shouldn't change when the annotation is modified (it definitely won't on the Kobo devices). Also, the hash can then be used to determine if the annotations have actually changed. If they haven't, the update of the metadata for the book can be skipped. This will mean the modification timestamp of the book will only change when there are actual changes to the metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions