Skip to content

Commit

Permalink
Merge pull request #667 from ZeitOnline/ZO-4270-ghost
Browse files Browse the repository at this point in the history
ZO-4270: Remove matching ghost before checkin, this avoids "-2" URLs in most common cases
  • Loading branch information
louika authored Mar 25, 2024
2 parents ceff352 + 1bc16a5 commit 198a56c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions core/docs/changelog/ghost.maint
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create workingcopy URLs with -2 less often
28 changes: 12 additions & 16 deletions core/src/zeit/ghost/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ checked out object:

>>> checked_out = ICheckoutManager(content).checkout()
>>> list(workingcopy.keys())
['4schanzentournee-abgesang-2']

Note that we have a different local name in the workingcopy. But this doesn't
matter and is not really visible for the user anyway. The uniqueId is correct
though:
['4schanzentournee-abgesang']

>>> checked_out.__name__
'4schanzentournee-abgesang-2'
'4schanzentournee-abgesang'
>>> checked_out.uniqueId
'http://xml.zeit.de/online/2007/01/4schanzentournee-abgesang'

Expand All @@ -73,7 +69,7 @@ When we do a temporary checkout no ghost will be added to the workingcopy:
>>> manager.checkin()
<zeit.cms.repository.unknown.PersistentUnknownResource...>
>>> list(workingcopy.keys())
['4schanzentournee-abgesang-2']
['4schanzentournee-abgesang']

Automatic ghost removing
========================
Expand Down Expand Up @@ -121,7 +117,7 @@ Content: Ford-Beerdigung
Content: Flugsicherheit
Content: EU-Beitritt-rumaenien-bulgarien
Content: Arbeitsmarktzahlen
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang


Checkin Flugsicherheit and Arbeitsmarktzahlen:
Expand All @@ -136,7 +132,7 @@ Content: Guantanamo
Content: Gesundheitsreform-Die
Content: Ford-Beerdigung
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang


We have exactly 7 objects in the workingcopy which is our target size. When we
Expand All @@ -152,7 +148,7 @@ Content: Guantanamo
Content: Gesundheitsreform-Die
Content: Ford-Beerdigung
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang

When we checkout yet another object, the last remaining ghost will be removed:

Expand All @@ -165,7 +161,7 @@ Content: Guantanamo
Content: Gesundheitsreform-Die
Content: Ford-Beerdigung
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang


After checking out another object, we'll have 8 objects int he workingcopy as
Expand All @@ -181,7 +177,7 @@ Content: Guantanamo
Content: Gesundheitsreform-Die
Content: Ford-Beerdigung
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang

When we check in a content now, we'll have a ghost despite the target size of
7:
Expand All @@ -197,7 +193,7 @@ Content: Querdax
Content: Guantanamo
Content: Ford-Beerdigung
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang

Checking in another object, still does not remove any ghost:

Expand All @@ -212,7 +208,7 @@ Content: Saarland
Content: Guantanamo
Content: Ford-Beerdigung
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang

Note that any invalid ghosts, that are ghosts which reference deleted objects,
are also removed when checking out any object.
Expand All @@ -236,7 +232,7 @@ Ghost : Gesundheitsreform-Die
Content: Saarland
Content: Guantanamo
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang



Expand All @@ -250,4 +246,4 @@ Ghost : Gesundheitsreform-Die
Content: Saarland
Content: Guantanamo
Content: EU-Beitritt-rumaenien-bulgarien
Content: 4schanzentournee-abgesang-2
Content: 4schanzentournee-abgesang
2 changes: 1 addition & 1 deletion core/src/zeit/ghost/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<configure xmlns="http://namespaces.zope.org/zope">

<subscriber handler=".ghost.add_ghost_after_checkin" />
<subscriber handler=".ghost.remove_ghost_after_checkout" />
<subscriber handler=".ghost.remove_ghost_on_checkout" />
<subscriber handler=".ghost.remove_excessive_ghosts" />

</configure>
Expand Down
4 changes: 2 additions & 2 deletions core/src/zeit/ghost/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def add_ghost_after_checkin(context, event):


@zope.component.adapter(
zeit.cms.interfaces.ICMSContent, zeit.cms.checkout.interfaces.IAfterCheckoutEvent
zeit.cms.interfaces.ICMSContent, zeit.cms.checkout.interfaces.IBeforeCheckoutEvent
)
def remove_ghost_after_checkout(context, event):
def remove_ghost_on_checkout(context, event):
"""Remove ghost of checked out object, if any."""
workingcopy = event.workingcopy
unique_id = context.uniqueId
Expand Down

0 comments on commit 198a56c

Please sign in to comment.