2
Vote

Feature Request:Scheduled publish / unpublish support on Custom Data Types

description

One use case is that, there's only 1 page, and a seperated folder containing all data items. Like Blogs, News, etc.

In this case, a data item is actually a 'page', so it make sense to enable users to schedule publish / unpublish date for data items ( instances of custom Data Type ) just like the pages.

comments

burningice wrote Apr 19 at 7:56 PM

Publish/unpublish for pages seems to be implemented quite clumpsy and very much as an afterthought :(

The best for you is most likely to create your own datafacade-classes for your data which handles the filtering based on a publish/unpublished schedule. An example of this is this generic teaser module which support setting these dates and handles the filtering before returning data-instances further up the chain

https://bitbucket.org/burningice/compositec1contrib/src/f76ff0a7bbb455e05723db1c660415c2da695e61/Teasers/Data/Types/ITeaser.cs?at=default#cl-26

https://bitbucket.org/burningice/compositec1contrib/src/f76ff0a7bbb455e05723db1c660415c2da695e61/Teasers/Data/TeaserFacade.cs?at=default#cl-136

elencala wrote Apr 20 at 7:34 AM

@burningice

Thank you for the quick and detailed response.

This approach seems neat comparing to the pages implementation.

Will it still benefit from c1 caching? When data changes, will it automatically refresh cache no matter which data store(xml/sql)?

burningice wrote Apr 20 at 11:44 AM

Depends what you have in mind when you say caching.

The most effective caching done by C1 is the Full Page Caching which only takes the modification of the actual page into account. Since the default duration is 60 seconds though, i wouldn't see it as a problem that some data doesn't get hidden/shown right on the exact second but maybe up to a minute later.

Another caching is in the Datalayer but it generally only works when you're querying data by its key. As soon as you have where-statements in there the query would continue down to the SQL database or xml-files, unless you do your own caching mechanisms.

Since this kind of publish/unpublish works using extra data on each record, its important always to do the filtering, since you can have "unpublished" data in the published table, but because the FilterPublishedDate method takes an IQueryable<T>, C1 is smart enough to append the WHERE to the actual sql-query being constructed and executed so there is no really overhead doing it this way. This is fundamentally different than the way C1 handles publish/unpublish of pages, where the datarecords actually are moved back and forth between the published and unpublished tables.

Another neat trick is that you can extend FilterPublishedDate a bit, and instead of hardcoding now to DateTime.Now, you could say that if you're logged in the C1 Console, and you have the querystring ?now=12-12-2014 in the pagerequest, then now should be the date specified in the querystring. This way you can preview how your page would look like on a certain date/time. Very very valuable when you ie. have some banners which should become visible on the 1st of December but you need to make sure how its going to look before hand.

elencala wrote Apr 20 at 7:36 PM

Yeah 60 seconds is totally fine in my case.

Regarding the Datalayer caching, just to make sure I'm not misunderstanding anything ( English is not my first language ). It only works when I query data by its key, means it doesn't work when I query a collection, nor FirstOrDefault from a collection. Correct?

From what I've been learning from this post, C1 full page caching caches the rendered pages ( html strings? ). If some data is modified, will it drop & rebuild the cache immediately or do it on the next 60-seconds checkpoint? When it does that, it just rebuild the 'changed' pages, right?

I'm going to read c1 doc again...

The neat trick you offered is very useful indeed. I'll try to implement it in my work. Since I'm quite new to C1 and this could be considered as my first c1 project, I'll be very appreciate if you point me some ways. :)

elencala wrote Apr 20 at 7:39 PM

Btw, C1 crashed when I was trying to install your Teaser package. Says it can't find CompositeC1Contrib.Sorting.dll. Manually copying the file to /bin could solve this. Then I tried to install Sorting package, but it crashed again, same error. A small bug maybe? C1 version 4.1.

burningice wrote Apr 20 at 8:08 PM

Nja... its because C1 package system doesn't really handle interdependencies between packages like NuGet does. The requirements for the Teaser package is
  • Sorting 1.4.1 which has a requirement on
  • Core 0.6 (which there isn't a package for)
I admit there could be an easier way to install the C1Contrib packages, but since they are generally not something simple out-of-the-box gallery-thingy or videoplayer which editors would quickly install and use, but fundamental building blocks developers would need i presume that most developers would be able to get them installed one way or the other.

There could also be some bindings to Razor 3.0 somewhere along the way, i know this will be updated and fixed in C1 for version 4.2 but until then, make sure to have the newest Web Pages and Razor binaries and do an assembly redirect in your web.config so all references to those assemblies are forwarded to version 3.0.0.0.

You can see here how C1 handles the Full Page caching https://bitbucket.org/actoas/composite-c1/src/b22758141cade32fa21625c782a6e64eb3600611/CompositeC1/Composite/Core/WebClient/ApplicationLevelEventHandlers.cs?at=default#cl-255. The Changeddate of a page gets a part of the cache key, meaning that as soon as an editor edits a page it will be flushed. As for Datalayer caching, then i would assume that every query which only involved a lookup on the key, that would be something like .FirstOrDefault(d => d.Id == ...), .Where(d => d.Id == ...), .Single(d => d.Id == ...) and so on would use some internal caching. But i'm not 100% sure.

elencala wrote Apr 21 at 7:09 PM

Thank you very much, I'll dive into it from there.

Anyway, will this become an out-of-box feature in C1 in the future? I think it should be a common requirement.